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