@valbuild/shared 0.61.0 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,6 @@ var core = require('@valbuild/core');
|
|
6
6
|
var marked = require('marked');
|
7
7
|
var zod = require('zod');
|
8
8
|
var fp = require('@valbuild/core/fp');
|
9
|
-
var patch = require('@valbuild/core/patch');
|
10
9
|
|
11
10
|
function _interopNamespace(e) {
|
12
11
|
if (e && e.__esModule) return e;
|
@@ -1999,16 +1998,15 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
1999
1998
|
return Constructor;
|
2000
1999
|
}
|
2001
2000
|
|
2002
|
-
var ops = new patch.JSONOps();
|
2003
2001
|
var ValStore = /*#__PURE__*/function () {
|
2004
2002
|
// uncertain whether this is the optimal way of returning
|
2005
2003
|
|
2006
2004
|
function ValStore(api) {
|
2007
2005
|
var _this = this;
|
2008
2006
|
_classCallCheck(this, ValStore);
|
2009
|
-
_defineProperty(this, "subscribe", function (
|
2007
|
+
_defineProperty(this, "subscribe", function (paths) {
|
2010
2008
|
return function (listener) {
|
2011
|
-
var subscriberId = createSubscriberId(
|
2009
|
+
var subscriberId = createSubscriberId(paths);
|
2012
2010
|
if (!_this.listeners[subscriberId]) {
|
2013
2011
|
_this.listeners[subscriberId] = [];
|
2014
2012
|
_this.subscribers.set(subscriberId, {});
|
@@ -2019,18 +2017,18 @@ var ValStore = /*#__PURE__*/function () {
|
|
2019
2017
|
};
|
2020
2018
|
};
|
2021
2019
|
});
|
2022
|
-
_defineProperty(this, "getSnapshot", function (
|
2020
|
+
_defineProperty(this, "getSnapshot", function (paths) {
|
2023
2021
|
return function () {
|
2024
|
-
return _this.get(
|
2022
|
+
return _this.get(paths);
|
2025
2023
|
};
|
2026
2024
|
});
|
2027
|
-
_defineProperty(this, "getServerSnapshot", function (
|
2025
|
+
_defineProperty(this, "getServerSnapshot", function (paths) {
|
2028
2026
|
return function () {
|
2029
|
-
return _this.get(
|
2027
|
+
return _this.get(paths);
|
2030
2028
|
};
|
2031
2029
|
});
|
2032
|
-
_defineProperty(this, "get", function (
|
2033
|
-
var subscriberId = createSubscriberId(
|
2030
|
+
_defineProperty(this, "get", function (paths) {
|
2031
|
+
var subscriberId = createSubscriberId(paths);
|
2034
2032
|
return _this.subscribers.get(subscriberId);
|
2035
2033
|
});
|
2036
2034
|
this.api = api;
|
@@ -2040,92 +2038,164 @@ var ValStore = /*#__PURE__*/function () {
|
|
2040
2038
|
this.schema = {};
|
2041
2039
|
}
|
2042
2040
|
_createClass(ValStore, [{
|
2041
|
+
key: "reset",
|
2042
|
+
value: function () {
|
2043
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
2044
|
+
var patches, allPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
2045
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
2046
|
+
while (1) switch (_context.prev = _context.next) {
|
2047
|
+
case 0:
|
2048
|
+
_context.next = 2;
|
2049
|
+
return this.api.getPatches();
|
2050
|
+
case 2:
|
2051
|
+
patches = _context.sent;
|
2052
|
+
if (!fp.result.isErr(patches)) {
|
2053
|
+
_context.next = 6;
|
2054
|
+
break;
|
2055
|
+
}
|
2056
|
+
console.error("Val: failed to get patches", patches.error);
|
2057
|
+
return _context.abrupt("return");
|
2058
|
+
case 6:
|
2059
|
+
allPatches = Object.values(patches.value).flatMap(function (mp) {
|
2060
|
+
return mp.map(function (p) {
|
2061
|
+
return p.patch_id;
|
2062
|
+
});
|
2063
|
+
});
|
2064
|
+
_context.next = 9;
|
2065
|
+
return this.api.putTree({
|
2066
|
+
patchIds: allPatches
|
2067
|
+
});
|
2068
|
+
case 9:
|
2069
|
+
data = _context.sent;
|
2070
|
+
_context.next = 12;
|
2071
|
+
return this.initialize();
|
2072
|
+
case 12:
|
2073
|
+
if (fp.result.isOk(data)) {
|
2074
|
+
for (_i = 0, _Object$keys = Object.keys(data.value.modules); _i < _Object$keys.length; _i++) {
|
2075
|
+
pathS = _Object$keys[_i];
|
2076
|
+
path = pathS;
|
2077
|
+
this.drafts[path] = data.value.modules[path].source;
|
2078
|
+
this.emitEvent(path, this.drafts[path]);
|
2079
|
+
for (_i2 = 0, _Array$from = Array.from(this.subscribers.entries()); _i2 < _Array$from.length; _i2++) {
|
2080
|
+
_Array$from$_i = _slicedToArray(_Array$from[_i2], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
|
2081
|
+
if (subscriberModules[path]) {
|
2082
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2083
|
+
this.emitChange(subscriberId);
|
2084
|
+
}
|
2085
|
+
}
|
2086
|
+
}
|
2087
|
+
} else {
|
2088
|
+
console.error("Val: failed to reset", data.error);
|
2089
|
+
}
|
2090
|
+
case 13:
|
2091
|
+
case "end":
|
2092
|
+
return _context.stop();
|
2093
|
+
}
|
2094
|
+
}, _callee, this);
|
2095
|
+
}));
|
2096
|
+
function reset() {
|
2097
|
+
return _reset.apply(this, arguments);
|
2098
|
+
}
|
2099
|
+
return reset;
|
2100
|
+
}()
|
2101
|
+
}, {
|
2043
2102
|
key: "getModule",
|
2044
2103
|
value: function () {
|
2045
|
-
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2104
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path) {
|
2046
2105
|
var refetch,
|
2047
2106
|
data,
|
2048
2107
|
fetchedSource,
|
2049
|
-
|
2050
|
-
|
2051
|
-
return _regeneratorRuntime().wrap(function
|
2052
|
-
while (1) switch (
|
2108
|
+
schema,
|
2109
|
+
_args2 = arguments;
|
2110
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
2111
|
+
while (1) switch (_context2.prev = _context2.next) {
|
2053
2112
|
case 0:
|
2054
|
-
refetch =
|
2055
|
-
if (!(!refetch && this.drafts[
|
2056
|
-
|
2113
|
+
refetch = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : false;
|
2114
|
+
if (!(!refetch && this.drafts[path] && this.schema[path])) {
|
2115
|
+
_context2.next = 3;
|
2057
2116
|
break;
|
2058
2117
|
}
|
2059
|
-
return
|
2060
|
-
source: this.drafts[
|
2061
|
-
schema: this.schema[
|
2118
|
+
return _context2.abrupt("return", fp.result.ok({
|
2119
|
+
source: this.drafts[path],
|
2120
|
+
schema: this.schema[path]
|
2062
2121
|
}));
|
2063
2122
|
case 3:
|
2064
|
-
|
2065
|
-
return this.api.
|
2066
|
-
|
2067
|
-
treePath: moduleId,
|
2068
|
-
includeSource: true,
|
2069
|
-
includeSchema: true
|
2123
|
+
_context2.next = 5;
|
2124
|
+
return this.api.putTree({
|
2125
|
+
treePath: path
|
2070
2126
|
});
|
2071
2127
|
case 5:
|
2072
|
-
data =
|
2128
|
+
data = _context2.sent;
|
2073
2129
|
if (!fp.result.isOk(data)) {
|
2074
|
-
|
2130
|
+
_context2.next = 26;
|
2075
2131
|
break;
|
2076
2132
|
}
|
2077
|
-
if (data.value.modules[
|
2078
|
-
|
2133
|
+
if (data.value.modules[path]) {
|
2134
|
+
_context2.next = 10;
|
2079
2135
|
break;
|
2080
2136
|
}
|
2081
2137
|
console.error("Val: could not find the module", {
|
2082
2138
|
moduleIds: Object.keys(data.value.modules),
|
2083
|
-
moduleId:
|
2139
|
+
moduleId: path,
|
2084
2140
|
data: data
|
2085
2141
|
});
|
2086
|
-
return
|
2087
|
-
message: "Could not fetch data.\nCould not find the module:\n" +
|
2142
|
+
return _context2.abrupt("return", fp.result.err({
|
2143
|
+
message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
|
2088
2144
|
}));
|
2089
2145
|
case 10:
|
2090
|
-
fetchedSource = data.value.modules[
|
2091
|
-
|
2092
|
-
if (
|
2093
|
-
|
2146
|
+
fetchedSource = data.value.modules[path].source;
|
2147
|
+
schema = this.schema[path];
|
2148
|
+
if (this.schema[path]) {
|
2149
|
+
_context2.next = 17;
|
2150
|
+
break;
|
2151
|
+
}
|
2152
|
+
_context2.next = 15;
|
2153
|
+
return this.initialize();
|
2154
|
+
case 15:
|
2155
|
+
if (this.schema[path]) {
|
2156
|
+
_context2.next = 17;
|
2094
2157
|
break;
|
2095
2158
|
}
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2159
|
+
return _context2.abrupt("return", fp.result.err({
|
2160
|
+
message: "Path not found in schema. Verify that the module exists."
|
2161
|
+
}));
|
2162
|
+
case 17:
|
2163
|
+
if (!(fetchedSource !== undefined)) {
|
2164
|
+
_context2.next = 22;
|
2165
|
+
break;
|
2166
|
+
}
|
2167
|
+
this.drafts[path] = fetchedSource;
|
2168
|
+
return _context2.abrupt("return", fp.result.ok({
|
2099
2169
|
source: fetchedSource,
|
2100
|
-
schema:
|
2170
|
+
schema: schema
|
2101
2171
|
}));
|
2102
|
-
case
|
2172
|
+
case 22:
|
2103
2173
|
console.error("Val: could not find the module source");
|
2104
|
-
return
|
2174
|
+
return _context2.abrupt("return", fp.result.err({
|
2105
2175
|
message: "Could not fetch data. Verify that the module exists."
|
2106
2176
|
}));
|
2107
|
-
case
|
2108
|
-
|
2177
|
+
case 24:
|
2178
|
+
_context2.next = 33;
|
2109
2179
|
break;
|
2110
|
-
case
|
2180
|
+
case 26:
|
2111
2181
|
if (!(data.error.statusCode === 504)) {
|
2112
|
-
|
2182
|
+
_context2.next = 31;
|
2113
2183
|
break;
|
2114
2184
|
}
|
2115
2185
|
console.error("Val: timeout", data.error);
|
2116
|
-
return
|
2186
|
+
return _context2.abrupt("return", fp.result.err({
|
2117
2187
|
message: "Timed out while fetching data. Try again later."
|
2118
2188
|
}));
|
2119
|
-
case
|
2189
|
+
case 31:
|
2120
2190
|
console.error("Val: failed to get module", data.error);
|
2121
|
-
return
|
2191
|
+
return _context2.abrupt("return", fp.result.err({
|
2122
2192
|
message: "Could not fetch data. Verify that Val is correctly configured."
|
2123
2193
|
}));
|
2124
|
-
case
|
2194
|
+
case 33:
|
2125
2195
|
case "end":
|
2126
|
-
return
|
2196
|
+
return _context2.stop();
|
2127
2197
|
}
|
2128
|
-
},
|
2198
|
+
}, _callee2, this);
|
2129
2199
|
}));
|
2130
2200
|
function getModule(_x) {
|
2131
2201
|
return _getModule.apply(this, arguments);
|
@@ -2135,180 +2205,105 @@ var ValStore = /*#__PURE__*/function () {
|
|
2135
2205
|
}, {
|
2136
2206
|
key: "applyPatch",
|
2137
2207
|
value: function () {
|
2138
|
-
var
|
2139
|
-
var
|
2140
|
-
return _regeneratorRuntime().wrap(function
|
2141
|
-
while (1) switch (
|
2208
|
+
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path, patchIds, patch) {
|
2209
|
+
var data, fetchedSource, _data$value$modules$p, _i3, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
|
2210
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2211
|
+
while (1) switch (_context3.prev = _context3.next) {
|
2142
2212
|
case 0:
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
patch: true,
|
2152
|
-
treePath: moduleId,
|
2153
|
-
includeSource: true,
|
2154
|
-
includeSchema: true
|
2213
|
+
_context3.next = 2;
|
2214
|
+
return this.api.putTree({
|
2215
|
+
treePath: path,
|
2216
|
+
patchIds: patchIds,
|
2217
|
+
addPatch: {
|
2218
|
+
path: path,
|
2219
|
+
patch: patch
|
2220
|
+
}
|
2155
2221
|
});
|
2156
|
-
case
|
2157
|
-
data =
|
2222
|
+
case 2:
|
2223
|
+
data = _context3.sent;
|
2158
2224
|
if (!fp.result.isOk(data)) {
|
2159
|
-
|
2225
|
+
_context3.next = 16;
|
2160
2226
|
break;
|
2161
2227
|
}
|
2162
|
-
fetchedSource = data.value.modules[
|
2163
|
-
|
2164
|
-
|
2165
|
-
_context2.next = 15;
|
2228
|
+
fetchedSource = data.value.modules[path].source;
|
2229
|
+
if (!(fetchedSource !== undefined)) {
|
2230
|
+
_context3.next = 12;
|
2166
2231
|
break;
|
2167
2232
|
}
|
2168
|
-
|
2169
|
-
this.
|
2170
|
-
this.
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2233
|
+
this.drafts[path] = fetchedSource;
|
2234
|
+
this.emitEvent(path, fetchedSource);
|
2235
|
+
for (_i3 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i3 < _Array$from2.length; _i3++) {
|
2236
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
|
2237
|
+
if (subscriberModules[path]) {
|
2238
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2239
|
+
this.emitChange(subscriberId);
|
2240
|
+
}
|
2241
|
+
}
|
2242
|
+
return _context3.abrupt("return", fp.result.ok(_defineProperty({}, path, {
|
2243
|
+
patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
|
2244
|
+
})));
|
2245
|
+
case 12:
|
2246
|
+
console.error("Val: could not patch");
|
2247
|
+
return _context3.abrupt("return", fp.result.err({
|
2176
2248
|
message: "Val: could not fetch data. Verify that the module exists."
|
2177
2249
|
}));
|
2178
|
-
case
|
2179
|
-
|
2250
|
+
case 14:
|
2251
|
+
_context3.next = 18;
|
2180
2252
|
break;
|
2181
|
-
case
|
2253
|
+
case 16:
|
2182
2254
|
console.error("Val: failed to get module", data.error);
|
2183
|
-
return
|
2255
|
+
return _context3.abrupt("return", fp.result.err({
|
2184
2256
|
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2185
2257
|
}));
|
2186
|
-
case
|
2187
|
-
_context2.next = 23;
|
2188
|
-
return this.api.postPatches(moduleId, patch$1);
|
2189
|
-
case 23:
|
2190
|
-
res = _context2.sent;
|
2191
|
-
if (!fp.result.isErr(res)) {
|
2192
|
-
_context2.next = 27;
|
2193
|
-
break;
|
2194
|
-
}
|
2195
|
-
console.error("Val: failed to post patch", res.error);
|
2196
|
-
return _context2.abrupt("return", res);
|
2197
|
-
case 27:
|
2198
|
-
patchRes = patch.applyPatch(currentSource, ops, patch$1.filter(core.Internal.notFileOp) // we cannot apply file ops here
|
2199
|
-
);
|
2200
|
-
if (!fp.result.isOk(patchRes)) {
|
2201
|
-
_context2.next = 35;
|
2202
|
-
break;
|
2203
|
-
}
|
2204
|
-
this.drafts[moduleId] = patchRes.value;
|
2205
|
-
this.emitEvent(moduleId, patchRes.value);
|
2206
|
-
for (_i = 0, _Array$from = Array.from(this.subscribers.entries()); _i < _Array$from.length; _i++) {
|
2207
|
-
_Array$from$_i = _slicedToArray(_Array$from[_i], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
|
2208
|
-
if (subscriberModules[moduleId]) {
|
2209
|
-
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, moduleId, this.drafts[moduleId])));
|
2210
|
-
this.emitChange(subscriberId);
|
2211
|
-
}
|
2212
|
-
}
|
2213
|
-
return _context2.abrupt("return", res);
|
2214
|
-
case 35:
|
2215
|
-
console.error("Val: failed to apply patch", patchRes.error);
|
2216
|
-
return _context2.abrupt("return", patchRes);
|
2217
|
-
case 37:
|
2258
|
+
case 18:
|
2218
2259
|
case "end":
|
2219
|
-
return
|
2260
|
+
return _context3.stop();
|
2220
2261
|
}
|
2221
|
-
},
|
2262
|
+
}, _callee3, this);
|
2222
2263
|
}));
|
2223
|
-
function applyPatch(_x2, _x3) {
|
2224
|
-
return
|
2264
|
+
function applyPatch(_x2, _x3, _x4) {
|
2265
|
+
return _applyPatch.apply(this, arguments);
|
2225
2266
|
}
|
2226
2267
|
return applyPatch;
|
2227
2268
|
}()
|
2228
2269
|
}, {
|
2229
2270
|
key: "emitEvent",
|
2230
|
-
value: function emitEvent(
|
2271
|
+
value: function emitEvent(path, source) {
|
2231
2272
|
var event = new CustomEvent("val-event", {
|
2232
2273
|
detail: {
|
2233
2274
|
type: "module-update",
|
2234
|
-
|
2275
|
+
path: path,
|
2235
2276
|
source: source
|
2236
2277
|
}
|
2237
2278
|
});
|
2238
2279
|
window.dispatchEvent(event);
|
2239
2280
|
}
|
2240
2281
|
}, {
|
2241
|
-
key: "
|
2242
|
-
value: function () {
|
2243
|
-
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(moduleIds) {
|
2244
|
-
var _this2 = this;
|
2245
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2246
|
-
while (1) switch (_context3.prev = _context3.next) {
|
2247
|
-
case 0:
|
2248
|
-
_context3.next = 2;
|
2249
|
-
return Promise.all(moduleIds.map(function (moduleId) {
|
2250
|
-
return _this2.updateTree(moduleId);
|
2251
|
-
}));
|
2252
|
-
case 2:
|
2253
|
-
case "end":
|
2254
|
-
return _context3.stop();
|
2255
|
-
}
|
2256
|
-
}, _callee3);
|
2257
|
-
}));
|
2258
|
-
function update(_x4) {
|
2259
|
-
return _update.apply(this, arguments);
|
2260
|
-
}
|
2261
|
-
return update;
|
2262
|
-
}()
|
2263
|
-
}, {
|
2264
|
-
key: "reset",
|
2282
|
+
key: "initialize",
|
2265
2283
|
value: function () {
|
2266
|
-
var
|
2284
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
2285
|
+
var data, paths, _i4, _arr, moduleId, schema, msg;
|
2267
2286
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2268
2287
|
while (1) switch (_context4.prev = _context4.next) {
|
2269
2288
|
case 0:
|
2270
|
-
|
2271
|
-
|
2272
|
-
case "end":
|
2273
|
-
return _context4.stop();
|
2274
|
-
}
|
2275
|
-
}, _callee4, this);
|
2276
|
-
}));
|
2277
|
-
function reset() {
|
2278
|
-
return _reset.apply(this, arguments);
|
2279
|
-
}
|
2280
|
-
return reset;
|
2281
|
-
}()
|
2282
|
-
}, {
|
2283
|
-
key: "initialize",
|
2284
|
-
value: function () {
|
2285
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
2286
|
-
var data, moduleIds, _i2, _arr, moduleId, schema, msg;
|
2287
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
2288
|
-
while (1) switch (_context5.prev = _context5.next) {
|
2289
|
-
case 0:
|
2290
|
-
_context5.next = 2;
|
2291
|
-
return this.api.getTree({
|
2292
|
-
patch: false,
|
2293
|
-
includeSource: false,
|
2294
|
-
includeSchema: true
|
2295
|
-
});
|
2289
|
+
_context4.next = 2;
|
2290
|
+
return this.api.getSchema({});
|
2296
2291
|
case 2:
|
2297
|
-
data =
|
2292
|
+
data = _context4.sent;
|
2298
2293
|
if (!fp.result.isOk(data)) {
|
2299
|
-
|
2294
|
+
_context4.next = 9;
|
2300
2295
|
break;
|
2301
2296
|
}
|
2302
|
-
|
2303
|
-
for (
|
2304
|
-
moduleId = _arr[
|
2305
|
-
schema = data.value.
|
2297
|
+
paths = [];
|
2298
|
+
for (_i4 = 0, _arr = Object.keys(data.value.schemas); _i4 < _arr.length; _i4++) {
|
2299
|
+
moduleId = _arr[_i4];
|
2300
|
+
schema = data.value.schemas[moduleId];
|
2306
2301
|
if (schema) {
|
2307
|
-
|
2302
|
+
paths.push(moduleId);
|
2308
2303
|
this.schema[moduleId] = schema;
|
2309
2304
|
}
|
2310
2305
|
}
|
2311
|
-
return
|
2306
|
+
return _context4.abrupt("return", fp.result.ok(paths));
|
2312
2307
|
case 9:
|
2313
2308
|
msg = "Failed to fetch content. ";
|
2314
2309
|
if (data.error.statusCode === 401) {
|
@@ -2316,7 +2311,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2316
2311
|
} else {
|
2317
2312
|
msg += "Get a developer to verify that Val is correctly setup.";
|
2318
2313
|
}
|
2319
|
-
return
|
2314
|
+
return _context4.abrupt("return", fp.result.err({
|
2320
2315
|
message: msg,
|
2321
2316
|
details: {
|
2322
2317
|
fetchError: data.error
|
@@ -2324,114 +2319,15 @@ var ValStore = /*#__PURE__*/function () {
|
|
2324
2319
|
}));
|
2325
2320
|
case 12:
|
2326
2321
|
case "end":
|
2327
|
-
return
|
2322
|
+
return _context4.stop();
|
2328
2323
|
}
|
2329
|
-
},
|
2324
|
+
}, _callee4, this);
|
2330
2325
|
}));
|
2331
2326
|
function initialize() {
|
2332
2327
|
return _initialize.apply(this, arguments);
|
2333
2328
|
}
|
2334
2329
|
return initialize;
|
2335
2330
|
}()
|
2336
|
-
}, {
|
2337
|
-
key: "updateTree",
|
2338
|
-
value: function () {
|
2339
|
-
var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(treePath) {
|
2340
|
-
var _this3 = this;
|
2341
|
-
var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i3, _arr2, _i4, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
|
2342
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
|
2343
|
-
while (1) switch (_context7.prev = _context7.next) {
|
2344
|
-
case 0:
|
2345
|
-
_context7.next = 2;
|
2346
|
-
return this.api.getTree({
|
2347
|
-
patch: true,
|
2348
|
-
treePath: treePath,
|
2349
|
-
includeSource: true,
|
2350
|
-
includeSchema: true
|
2351
|
-
});
|
2352
|
-
case 2:
|
2353
|
-
data = _context7.sent;
|
2354
|
-
moduleIds = [];
|
2355
|
-
if (!fp.result.isOk(data)) {
|
2356
|
-
_context7.next = 18;
|
2357
|
-
break;
|
2358
|
-
}
|
2359
|
-
updatedSubscriberIds = new Map();
|
2360
|
-
subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
|
2361
|
-
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
2362
|
-
var moduleId, source, updatedSubscriberId;
|
2363
|
-
return _regeneratorRuntime().wrap(function _loop$(_context6) {
|
2364
|
-
while (1) switch (_context6.prev = _context6.next) {
|
2365
|
-
case 0:
|
2366
|
-
moduleId = _arr2[_i3];
|
2367
|
-
source = data.value.modules[moduleId].source;
|
2368
|
-
if (typeof source !== "undefined") {
|
2369
|
-
moduleIds.push(moduleId);
|
2370
|
-
_this3.emitEvent(moduleId, source);
|
2371
|
-
updatedSubscriberId = subscriberIds.find(function (subscriberId) {
|
2372
|
-
return subscriberId.includes(moduleId);
|
2373
|
-
} // NOTE: dependent on
|
2374
|
-
);
|
2375
|
-
if (updatedSubscriberId) {
|
2376
|
-
updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
|
2377
|
-
}
|
2378
|
-
}
|
2379
|
-
case 3:
|
2380
|
-
case "end":
|
2381
|
-
return _context6.stop();
|
2382
|
-
}
|
2383
|
-
}, _loop);
|
2384
|
-
});
|
2385
|
-
_i3 = 0, _arr2 = Object.keys(data.value.modules);
|
2386
|
-
case 9:
|
2387
|
-
if (!(_i3 < _arr2.length)) {
|
2388
|
-
_context7.next = 14;
|
2389
|
-
break;
|
2390
|
-
}
|
2391
|
-
return _context7.delegateYield(_loop(), "t0", 11);
|
2392
|
-
case 11:
|
2393
|
-
_i3++;
|
2394
|
-
_context7.next = 9;
|
2395
|
-
break;
|
2396
|
-
case 14:
|
2397
|
-
// For all updated subscribers: set new module data and emit change
|
2398
|
-
for (_i4 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i4 < _Array$from2.length; _i4++) {
|
2399
|
-
_Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
|
2400
|
-
subscriberModules = Object.fromEntries(_moduleIds.flatMap(function (moduleId) {
|
2401
|
-
var source = data.value.modules[moduleId].source;
|
2402
|
-
if (!source) {
|
2403
|
-
return [];
|
2404
|
-
}
|
2405
|
-
return [[moduleId, source]];
|
2406
|
-
}));
|
2407
|
-
this.subscribers.set(updatedSubscriberId, subscriberModules);
|
2408
|
-
this.emitChange(updatedSubscriberId);
|
2409
|
-
}
|
2410
|
-
return _context7.abrupt("return", fp.result.ok(moduleIds));
|
2411
|
-
case 18:
|
2412
|
-
msg = "Failed to fetch content. ";
|
2413
|
-
if (data.error.statusCode === 401) {
|
2414
|
-
msg += "Authorization failed - check that you are logged in.";
|
2415
|
-
} else {
|
2416
|
-
msg += "Get a developer to verify that Val is correctly setup.";
|
2417
|
-
}
|
2418
|
-
return _context7.abrupt("return", fp.result.err({
|
2419
|
-
message: msg,
|
2420
|
-
details: {
|
2421
|
-
fetchError: data.error
|
2422
|
-
}
|
2423
|
-
}));
|
2424
|
-
case 21:
|
2425
|
-
case "end":
|
2426
|
-
return _context7.stop();
|
2427
|
-
}
|
2428
|
-
}, _callee6, this);
|
2429
|
-
}));
|
2430
|
-
function updateTree(_x5) {
|
2431
|
-
return _updateTree.apply(this, arguments);
|
2432
|
-
}
|
2433
|
-
return updateTree;
|
2434
|
-
}()
|
2435
2331
|
}, {
|
2436
2332
|
key: "emitChange",
|
2437
2333
|
value: function emitChange(subscriberId) {
|
@@ -2451,8 +2347,8 @@ var ValStore = /*#__PURE__*/function () {
|
|
2451
2347
|
}]);
|
2452
2348
|
return ValStore;
|
2453
2349
|
}();
|
2454
|
-
function createSubscriberId(
|
2455
|
-
return
|
2350
|
+
function createSubscriberId(paths) {
|
2351
|
+
return paths.slice().sort().join("&");
|
2456
2352
|
}
|
2457
2353
|
|
2458
2354
|
exports.EXT_TO_MIME_TYPES = EXT_TO_MIME_TYPES;
|