@valbuild/shared 0.60.18 → 0.60.20

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.
@@ -30,6 +30,15 @@ export declare class ValStore {
30
30
  };
31
31
  };
32
32
  }>>;
33
+ initialize(): Promise<result.Result<ModuleId[], {
34
+ message: string;
35
+ details: {
36
+ fetchError: {
37
+ message: string;
38
+ statusCode?: number;
39
+ };
40
+ };
41
+ }>>;
33
42
  private updateTree;
34
43
  subscribe: (moduleIds: ModuleId[]) => (listener: () => void) => () => void;
35
44
  private emitChange;
@@ -2065,7 +2065,9 @@ var ValStore = /*#__PURE__*/function () {
2065
2065
  return this.api.getTree({
2066
2066
  patch: true,
2067
2067
  treePath: moduleId,
2068
- includeSource: true
2068
+ includeSource: true,
2069
+ includeSchema: true,
2070
+ validate: true
2069
2071
  });
2070
2072
  case 5:
2071
2073
  data = _context.sent;
@@ -2079,7 +2081,8 @@ var ValStore = /*#__PURE__*/function () {
2079
2081
  }
2080
2082
  console.error("Val: could not find the module", {
2081
2083
  moduleIds: Object.keys(data.value.modules),
2082
- moduleId: moduleId
2084
+ moduleId: moduleId,
2085
+ data: data
2083
2086
  });
2084
2087
  return _context.abrupt("return", fp.result.err({
2085
2088
  message: "Could not fetch data. Could not find the module: " + moduleId + ". Verify that the module id and file name is correct."
@@ -2103,14 +2106,23 @@ var ValStore = /*#__PURE__*/function () {
2103
2106
  message: "Could not fetch data. Verify that the module exists."
2104
2107
  }));
2105
2108
  case 20:
2106
- _context.next = 24;
2109
+ _context.next = 29;
2107
2110
  break;
2108
2111
  case 22:
2112
+ if (!(data.error.statusCode === 504)) {
2113
+ _context.next = 27;
2114
+ break;
2115
+ }
2116
+ console.error("Val: timeout", data.error);
2117
+ return _context.abrupt("return", fp.result.err({
2118
+ message: "Timed out while fetching data. Try again later."
2119
+ }));
2120
+ case 27:
2109
2121
  console.error("Val: failed to get module", data.error);
2110
2122
  return _context.abrupt("return", fp.result.err({
2111
2123
  message: "Could not fetch data. Verify that Val is correctly configured."
2112
2124
  }));
2113
- case 24:
2125
+ case 29:
2114
2126
  case "end":
2115
2127
  return _context.stop();
2116
2128
  }
@@ -2139,7 +2151,9 @@ var ValStore = /*#__PURE__*/function () {
2139
2151
  return this.api.getTree({
2140
2152
  patch: true,
2141
2153
  treePath: moduleId,
2142
- includeSource: true
2154
+ includeSource: true,
2155
+ includeSchema: true,
2156
+ validate: true
2143
2157
  });
2144
2158
  case 5:
2145
2159
  data = _context2.sent;
@@ -2267,39 +2281,96 @@ var ValStore = /*#__PURE__*/function () {
2267
2281
  }
2268
2282
  return reset;
2269
2283
  }()
2284
+ }, {
2285
+ key: "initialize",
2286
+ value: function () {
2287
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2288
+ var data, moduleIds, _i2, _arr, moduleId, schema, msg;
2289
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2290
+ while (1) switch (_context5.prev = _context5.next) {
2291
+ case 0:
2292
+ _context5.next = 2;
2293
+ return this.api.getTree({
2294
+ patch: false,
2295
+ includeSource: false,
2296
+ includeSchema: true,
2297
+ validate: false
2298
+ });
2299
+ case 2:
2300
+ data = _context5.sent;
2301
+ if (!fp.result.isOk(data)) {
2302
+ _context5.next = 9;
2303
+ break;
2304
+ }
2305
+ moduleIds = [];
2306
+ for (_i2 = 0, _arr = Object.keys(data.value.modules); _i2 < _arr.length; _i2++) {
2307
+ moduleId = _arr[_i2];
2308
+ schema = data.value.modules[moduleId].schema;
2309
+ if (schema) {
2310
+ moduleIds.push(moduleId);
2311
+ this.schema[moduleId] = schema;
2312
+ }
2313
+ }
2314
+ return _context5.abrupt("return", fp.result.ok(moduleIds));
2315
+ case 9:
2316
+ msg = "Failed to fetch content. ";
2317
+ if (data.error.statusCode === 401) {
2318
+ msg += "Authorization failed - check that you are logged in.";
2319
+ } else {
2320
+ msg += "Get a developer to verify that Val is correctly setup.";
2321
+ }
2322
+ return _context5.abrupt("return", fp.result.err({
2323
+ message: msg,
2324
+ details: {
2325
+ fetchError: data.error
2326
+ }
2327
+ }));
2328
+ case 12:
2329
+ case "end":
2330
+ return _context5.stop();
2331
+ }
2332
+ }, _callee5, this);
2333
+ }));
2334
+ function initialize() {
2335
+ return _initialize.apply(this, arguments);
2336
+ }
2337
+ return initialize;
2338
+ }()
2270
2339
  }, {
2271
2340
  key: "updateTree",
2272
2341
  value: function () {
2273
- var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2342
+ var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(treePath) {
2274
2343
  var _this3 = this;
2275
- var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2276
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2277
- while (1) switch (_context6.prev = _context6.next) {
2344
+ var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i3, _arr2, _i4, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2345
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
2346
+ while (1) switch (_context7.prev = _context7.next) {
2278
2347
  case 0:
2279
- _context6.next = 2;
2348
+ _context7.next = 2;
2280
2349
  return this.api.getTree({
2281
2350
  patch: true,
2282
2351
  treePath: treePath,
2283
- includeSource: true
2352
+ includeSource: true,
2353
+ includeSchema: true,
2354
+ validate: true
2284
2355
  });
2285
2356
  case 2:
2286
- data = _context6.sent;
2357
+ data = _context7.sent;
2287
2358
  moduleIds = [];
2288
2359
  if (!fp.result.isOk(data)) {
2289
- _context6.next = 18;
2360
+ _context7.next = 18;
2290
2361
  break;
2291
2362
  }
2292
2363
  updatedSubscriberIds = new Map();
2293
2364
  subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
2294
2365
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
2295
2366
  var moduleId, source, updatedSubscriberId;
2296
- return _regeneratorRuntime().wrap(function _loop$(_context5) {
2297
- while (1) switch (_context5.prev = _context5.next) {
2367
+ return _regeneratorRuntime().wrap(function _loop$(_context6) {
2368
+ while (1) switch (_context6.prev = _context6.next) {
2298
2369
  case 0:
2299
- moduleId = _arr[_i2];
2300
- moduleIds.push(moduleId);
2370
+ moduleId = _arr2[_i3];
2301
2371
  source = data.value.modules[moduleId].source;
2302
2372
  if (typeof source !== "undefined") {
2373
+ moduleIds.push(moduleId);
2303
2374
  _this3.emitEvent(moduleId, source);
2304
2375
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2305
2376
  return subscriberId.includes(moduleId);
@@ -2309,27 +2380,27 @@ var ValStore = /*#__PURE__*/function () {
2309
2380
  updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
2310
2381
  }
2311
2382
  }
2312
- case 4:
2383
+ case 3:
2313
2384
  case "end":
2314
- return _context5.stop();
2385
+ return _context6.stop();
2315
2386
  }
2316
2387
  }, _loop);
2317
2388
  });
2318
- _i2 = 0, _arr = Object.keys(data.value.modules);
2389
+ _i3 = 0, _arr2 = Object.keys(data.value.modules);
2319
2390
  case 9:
2320
- if (!(_i2 < _arr.length)) {
2321
- _context6.next = 14;
2391
+ if (!(_i3 < _arr2.length)) {
2392
+ _context7.next = 14;
2322
2393
  break;
2323
2394
  }
2324
- return _context6.delegateYield(_loop(), "t0", 11);
2395
+ return _context7.delegateYield(_loop(), "t0", 11);
2325
2396
  case 11:
2326
- _i2++;
2327
- _context6.next = 9;
2397
+ _i3++;
2398
+ _context7.next = 9;
2328
2399
  break;
2329
2400
  case 14:
2330
2401
  // For all updated subscribers: set new module data and emit change
2331
- for (_i3 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i3 < _Array$from2.length; _i3++) {
2332
- _Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2402
+ for (_i4 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i4 < _Array$from2.length; _i4++) {
2403
+ _Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2333
2404
  subscriberModules = Object.fromEntries(_moduleIds.flatMap(function (moduleId) {
2334
2405
  var source = data.value.modules[moduleId].source;
2335
2406
  if (!source) {
@@ -2340,7 +2411,7 @@ var ValStore = /*#__PURE__*/function () {
2340
2411
  this.subscribers.set(updatedSubscriberId, subscriberModules);
2341
2412
  this.emitChange(updatedSubscriberId);
2342
2413
  }
2343
- return _context6.abrupt("return", fp.result.ok(moduleIds));
2414
+ return _context7.abrupt("return", fp.result.ok(moduleIds));
2344
2415
  case 18:
2345
2416
  msg = "Failed to fetch content. ";
2346
2417
  if (data.error.statusCode === 401) {
@@ -2348,7 +2419,7 @@ var ValStore = /*#__PURE__*/function () {
2348
2419
  } else {
2349
2420
  msg += "Get a developer to verify that Val is correctly setup.";
2350
2421
  }
2351
- return _context6.abrupt("return", fp.result.err({
2422
+ return _context7.abrupt("return", fp.result.err({
2352
2423
  message: msg,
2353
2424
  details: {
2354
2425
  fetchError: data.error
@@ -2356,9 +2427,9 @@ var ValStore = /*#__PURE__*/function () {
2356
2427
  }));
2357
2428
  case 21:
2358
2429
  case "end":
2359
- return _context6.stop();
2430
+ return _context7.stop();
2360
2431
  }
2361
- }, _callee5, this);
2432
+ }, _callee6, this);
2362
2433
  }));
2363
2434
  function updateTree(_x5) {
2364
2435
  return _updateTree.apply(this, arguments);
@@ -2065,7 +2065,9 @@ var ValStore = /*#__PURE__*/function () {
2065
2065
  return this.api.getTree({
2066
2066
  patch: true,
2067
2067
  treePath: moduleId,
2068
- includeSource: true
2068
+ includeSource: true,
2069
+ includeSchema: true,
2070
+ validate: true
2069
2071
  });
2070
2072
  case 5:
2071
2073
  data = _context.sent;
@@ -2079,7 +2081,8 @@ var ValStore = /*#__PURE__*/function () {
2079
2081
  }
2080
2082
  console.error("Val: could not find the module", {
2081
2083
  moduleIds: Object.keys(data.value.modules),
2082
- moduleId: moduleId
2084
+ moduleId: moduleId,
2085
+ data: data
2083
2086
  });
2084
2087
  return _context.abrupt("return", fp.result.err({
2085
2088
  message: "Could not fetch data. Could not find the module: " + moduleId + ". Verify that the module id and file name is correct."
@@ -2103,14 +2106,23 @@ var ValStore = /*#__PURE__*/function () {
2103
2106
  message: "Could not fetch data. Verify that the module exists."
2104
2107
  }));
2105
2108
  case 20:
2106
- _context.next = 24;
2109
+ _context.next = 29;
2107
2110
  break;
2108
2111
  case 22:
2112
+ if (!(data.error.statusCode === 504)) {
2113
+ _context.next = 27;
2114
+ break;
2115
+ }
2116
+ console.error("Val: timeout", data.error);
2117
+ return _context.abrupt("return", fp.result.err({
2118
+ message: "Timed out while fetching data. Try again later."
2119
+ }));
2120
+ case 27:
2109
2121
  console.error("Val: failed to get module", data.error);
2110
2122
  return _context.abrupt("return", fp.result.err({
2111
2123
  message: "Could not fetch data. Verify that Val is correctly configured."
2112
2124
  }));
2113
- case 24:
2125
+ case 29:
2114
2126
  case "end":
2115
2127
  return _context.stop();
2116
2128
  }
@@ -2139,7 +2151,9 @@ var ValStore = /*#__PURE__*/function () {
2139
2151
  return this.api.getTree({
2140
2152
  patch: true,
2141
2153
  treePath: moduleId,
2142
- includeSource: true
2154
+ includeSource: true,
2155
+ includeSchema: true,
2156
+ validate: true
2143
2157
  });
2144
2158
  case 5:
2145
2159
  data = _context2.sent;
@@ -2267,39 +2281,96 @@ var ValStore = /*#__PURE__*/function () {
2267
2281
  }
2268
2282
  return reset;
2269
2283
  }()
2284
+ }, {
2285
+ key: "initialize",
2286
+ value: function () {
2287
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2288
+ var data, moduleIds, _i2, _arr, moduleId, schema, msg;
2289
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2290
+ while (1) switch (_context5.prev = _context5.next) {
2291
+ case 0:
2292
+ _context5.next = 2;
2293
+ return this.api.getTree({
2294
+ patch: false,
2295
+ includeSource: false,
2296
+ includeSchema: true,
2297
+ validate: false
2298
+ });
2299
+ case 2:
2300
+ data = _context5.sent;
2301
+ if (!fp.result.isOk(data)) {
2302
+ _context5.next = 9;
2303
+ break;
2304
+ }
2305
+ moduleIds = [];
2306
+ for (_i2 = 0, _arr = Object.keys(data.value.modules); _i2 < _arr.length; _i2++) {
2307
+ moduleId = _arr[_i2];
2308
+ schema = data.value.modules[moduleId].schema;
2309
+ if (schema) {
2310
+ moduleIds.push(moduleId);
2311
+ this.schema[moduleId] = schema;
2312
+ }
2313
+ }
2314
+ return _context5.abrupt("return", fp.result.ok(moduleIds));
2315
+ case 9:
2316
+ msg = "Failed to fetch content. ";
2317
+ if (data.error.statusCode === 401) {
2318
+ msg += "Authorization failed - check that you are logged in.";
2319
+ } else {
2320
+ msg += "Get a developer to verify that Val is correctly setup.";
2321
+ }
2322
+ return _context5.abrupt("return", fp.result.err({
2323
+ message: msg,
2324
+ details: {
2325
+ fetchError: data.error
2326
+ }
2327
+ }));
2328
+ case 12:
2329
+ case "end":
2330
+ return _context5.stop();
2331
+ }
2332
+ }, _callee5, this);
2333
+ }));
2334
+ function initialize() {
2335
+ return _initialize.apply(this, arguments);
2336
+ }
2337
+ return initialize;
2338
+ }()
2270
2339
  }, {
2271
2340
  key: "updateTree",
2272
2341
  value: function () {
2273
- var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2342
+ var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(treePath) {
2274
2343
  var _this3 = this;
2275
- var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2276
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2277
- while (1) switch (_context6.prev = _context6.next) {
2344
+ var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i3, _arr2, _i4, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2345
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
2346
+ while (1) switch (_context7.prev = _context7.next) {
2278
2347
  case 0:
2279
- _context6.next = 2;
2348
+ _context7.next = 2;
2280
2349
  return this.api.getTree({
2281
2350
  patch: true,
2282
2351
  treePath: treePath,
2283
- includeSource: true
2352
+ includeSource: true,
2353
+ includeSchema: true,
2354
+ validate: true
2284
2355
  });
2285
2356
  case 2:
2286
- data = _context6.sent;
2357
+ data = _context7.sent;
2287
2358
  moduleIds = [];
2288
2359
  if (!fp.result.isOk(data)) {
2289
- _context6.next = 18;
2360
+ _context7.next = 18;
2290
2361
  break;
2291
2362
  }
2292
2363
  updatedSubscriberIds = new Map();
2293
2364
  subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
2294
2365
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
2295
2366
  var moduleId, source, updatedSubscriberId;
2296
- return _regeneratorRuntime().wrap(function _loop$(_context5) {
2297
- while (1) switch (_context5.prev = _context5.next) {
2367
+ return _regeneratorRuntime().wrap(function _loop$(_context6) {
2368
+ while (1) switch (_context6.prev = _context6.next) {
2298
2369
  case 0:
2299
- moduleId = _arr[_i2];
2300
- moduleIds.push(moduleId);
2370
+ moduleId = _arr2[_i3];
2301
2371
  source = data.value.modules[moduleId].source;
2302
2372
  if (typeof source !== "undefined") {
2373
+ moduleIds.push(moduleId);
2303
2374
  _this3.emitEvent(moduleId, source);
2304
2375
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2305
2376
  return subscriberId.includes(moduleId);
@@ -2309,27 +2380,27 @@ var ValStore = /*#__PURE__*/function () {
2309
2380
  updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
2310
2381
  }
2311
2382
  }
2312
- case 4:
2383
+ case 3:
2313
2384
  case "end":
2314
- return _context5.stop();
2385
+ return _context6.stop();
2315
2386
  }
2316
2387
  }, _loop);
2317
2388
  });
2318
- _i2 = 0, _arr = Object.keys(data.value.modules);
2389
+ _i3 = 0, _arr2 = Object.keys(data.value.modules);
2319
2390
  case 9:
2320
- if (!(_i2 < _arr.length)) {
2321
- _context6.next = 14;
2391
+ if (!(_i3 < _arr2.length)) {
2392
+ _context7.next = 14;
2322
2393
  break;
2323
2394
  }
2324
- return _context6.delegateYield(_loop(), "t0", 11);
2395
+ return _context7.delegateYield(_loop(), "t0", 11);
2325
2396
  case 11:
2326
- _i2++;
2327
- _context6.next = 9;
2397
+ _i3++;
2398
+ _context7.next = 9;
2328
2399
  break;
2329
2400
  case 14:
2330
2401
  // For all updated subscribers: set new module data and emit change
2331
- for (_i3 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i3 < _Array$from2.length; _i3++) {
2332
- _Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2402
+ for (_i4 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i4 < _Array$from2.length; _i4++) {
2403
+ _Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2333
2404
  subscriberModules = Object.fromEntries(_moduleIds.flatMap(function (moduleId) {
2334
2405
  var source = data.value.modules[moduleId].source;
2335
2406
  if (!source) {
@@ -2340,7 +2411,7 @@ var ValStore = /*#__PURE__*/function () {
2340
2411
  this.subscribers.set(updatedSubscriberId, subscriberModules);
2341
2412
  this.emitChange(updatedSubscriberId);
2342
2413
  }
2343
- return _context6.abrupt("return", fp.result.ok(moduleIds));
2414
+ return _context7.abrupt("return", fp.result.ok(moduleIds));
2344
2415
  case 18:
2345
2416
  msg = "Failed to fetch content. ";
2346
2417
  if (data.error.statusCode === 401) {
@@ -2348,7 +2419,7 @@ var ValStore = /*#__PURE__*/function () {
2348
2419
  } else {
2349
2420
  msg += "Get a developer to verify that Val is correctly setup.";
2350
2421
  }
2351
- return _context6.abrupt("return", fp.result.err({
2422
+ return _context7.abrupt("return", fp.result.err({
2352
2423
  message: msg,
2353
2424
  details: {
2354
2425
  fetchError: data.error
@@ -2356,9 +2427,9 @@ var ValStore = /*#__PURE__*/function () {
2356
2427
  }));
2357
2428
  case 21:
2358
2429
  case "end":
2359
- return _context6.stop();
2430
+ return _context7.stop();
2360
2431
  }
2361
- }, _callee5, this);
2432
+ }, _callee6, this);
2362
2433
  }));
2363
2434
  function updateTree(_x5) {
2364
2435
  return _updateTree.apply(this, arguments);
@@ -2041,7 +2041,9 @@ var ValStore = /*#__PURE__*/function () {
2041
2041
  return this.api.getTree({
2042
2042
  patch: true,
2043
2043
  treePath: moduleId,
2044
- includeSource: true
2044
+ includeSource: true,
2045
+ includeSchema: true,
2046
+ validate: true
2045
2047
  });
2046
2048
  case 5:
2047
2049
  data = _context.sent;
@@ -2055,7 +2057,8 @@ var ValStore = /*#__PURE__*/function () {
2055
2057
  }
2056
2058
  console.error("Val: could not find the module", {
2057
2059
  moduleIds: Object.keys(data.value.modules),
2058
- moduleId: moduleId
2060
+ moduleId: moduleId,
2061
+ data: data
2059
2062
  });
2060
2063
  return _context.abrupt("return", result.err({
2061
2064
  message: "Could not fetch data. Could not find the module: " + moduleId + ". Verify that the module id and file name is correct."
@@ -2079,14 +2082,23 @@ var ValStore = /*#__PURE__*/function () {
2079
2082
  message: "Could not fetch data. Verify that the module exists."
2080
2083
  }));
2081
2084
  case 20:
2082
- _context.next = 24;
2085
+ _context.next = 29;
2083
2086
  break;
2084
2087
  case 22:
2088
+ if (!(data.error.statusCode === 504)) {
2089
+ _context.next = 27;
2090
+ break;
2091
+ }
2092
+ console.error("Val: timeout", data.error);
2093
+ return _context.abrupt("return", result.err({
2094
+ message: "Timed out while fetching data. Try again later."
2095
+ }));
2096
+ case 27:
2085
2097
  console.error("Val: failed to get module", data.error);
2086
2098
  return _context.abrupt("return", result.err({
2087
2099
  message: "Could not fetch data. Verify that Val is correctly configured."
2088
2100
  }));
2089
- case 24:
2101
+ case 29:
2090
2102
  case "end":
2091
2103
  return _context.stop();
2092
2104
  }
@@ -2115,7 +2127,9 @@ var ValStore = /*#__PURE__*/function () {
2115
2127
  return this.api.getTree({
2116
2128
  patch: true,
2117
2129
  treePath: moduleId,
2118
- includeSource: true
2130
+ includeSource: true,
2131
+ includeSchema: true,
2132
+ validate: true
2119
2133
  });
2120
2134
  case 5:
2121
2135
  data = _context2.sent;
@@ -2243,39 +2257,96 @@ var ValStore = /*#__PURE__*/function () {
2243
2257
  }
2244
2258
  return reset;
2245
2259
  }()
2260
+ }, {
2261
+ key: "initialize",
2262
+ value: function () {
2263
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
2264
+ var data, moduleIds, _i2, _arr, moduleId, schema, msg;
2265
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2266
+ while (1) switch (_context5.prev = _context5.next) {
2267
+ case 0:
2268
+ _context5.next = 2;
2269
+ return this.api.getTree({
2270
+ patch: false,
2271
+ includeSource: false,
2272
+ includeSchema: true,
2273
+ validate: false
2274
+ });
2275
+ case 2:
2276
+ data = _context5.sent;
2277
+ if (!result.isOk(data)) {
2278
+ _context5.next = 9;
2279
+ break;
2280
+ }
2281
+ moduleIds = [];
2282
+ for (_i2 = 0, _arr = Object.keys(data.value.modules); _i2 < _arr.length; _i2++) {
2283
+ moduleId = _arr[_i2];
2284
+ schema = data.value.modules[moduleId].schema;
2285
+ if (schema) {
2286
+ moduleIds.push(moduleId);
2287
+ this.schema[moduleId] = schema;
2288
+ }
2289
+ }
2290
+ return _context5.abrupt("return", result.ok(moduleIds));
2291
+ case 9:
2292
+ msg = "Failed to fetch content. ";
2293
+ if (data.error.statusCode === 401) {
2294
+ msg += "Authorization failed - check that you are logged in.";
2295
+ } else {
2296
+ msg += "Get a developer to verify that Val is correctly setup.";
2297
+ }
2298
+ return _context5.abrupt("return", result.err({
2299
+ message: msg,
2300
+ details: {
2301
+ fetchError: data.error
2302
+ }
2303
+ }));
2304
+ case 12:
2305
+ case "end":
2306
+ return _context5.stop();
2307
+ }
2308
+ }, _callee5, this);
2309
+ }));
2310
+ function initialize() {
2311
+ return _initialize.apply(this, arguments);
2312
+ }
2313
+ return initialize;
2314
+ }()
2246
2315
  }, {
2247
2316
  key: "updateTree",
2248
2317
  value: function () {
2249
- var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2318
+ var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(treePath) {
2250
2319
  var _this3 = this;
2251
- var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2252
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2253
- while (1) switch (_context6.prev = _context6.next) {
2320
+ var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i3, _arr2, _i4, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2321
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
2322
+ while (1) switch (_context7.prev = _context7.next) {
2254
2323
  case 0:
2255
- _context6.next = 2;
2324
+ _context7.next = 2;
2256
2325
  return this.api.getTree({
2257
2326
  patch: true,
2258
2327
  treePath: treePath,
2259
- includeSource: true
2328
+ includeSource: true,
2329
+ includeSchema: true,
2330
+ validate: true
2260
2331
  });
2261
2332
  case 2:
2262
- data = _context6.sent;
2333
+ data = _context7.sent;
2263
2334
  moduleIds = [];
2264
2335
  if (!result.isOk(data)) {
2265
- _context6.next = 18;
2336
+ _context7.next = 18;
2266
2337
  break;
2267
2338
  }
2268
2339
  updatedSubscriberIds = new Map();
2269
2340
  subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
2270
2341
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
2271
2342
  var moduleId, source, updatedSubscriberId;
2272
- return _regeneratorRuntime().wrap(function _loop$(_context5) {
2273
- while (1) switch (_context5.prev = _context5.next) {
2343
+ return _regeneratorRuntime().wrap(function _loop$(_context6) {
2344
+ while (1) switch (_context6.prev = _context6.next) {
2274
2345
  case 0:
2275
- moduleId = _arr[_i2];
2276
- moduleIds.push(moduleId);
2346
+ moduleId = _arr2[_i3];
2277
2347
  source = data.value.modules[moduleId].source;
2278
2348
  if (typeof source !== "undefined") {
2349
+ moduleIds.push(moduleId);
2279
2350
  _this3.emitEvent(moduleId, source);
2280
2351
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2281
2352
  return subscriberId.includes(moduleId);
@@ -2285,27 +2356,27 @@ var ValStore = /*#__PURE__*/function () {
2285
2356
  updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
2286
2357
  }
2287
2358
  }
2288
- case 4:
2359
+ case 3:
2289
2360
  case "end":
2290
- return _context5.stop();
2361
+ return _context6.stop();
2291
2362
  }
2292
2363
  }, _loop);
2293
2364
  });
2294
- _i2 = 0, _arr = Object.keys(data.value.modules);
2365
+ _i3 = 0, _arr2 = Object.keys(data.value.modules);
2295
2366
  case 9:
2296
- if (!(_i2 < _arr.length)) {
2297
- _context6.next = 14;
2367
+ if (!(_i3 < _arr2.length)) {
2368
+ _context7.next = 14;
2298
2369
  break;
2299
2370
  }
2300
- return _context6.delegateYield(_loop(), "t0", 11);
2371
+ return _context7.delegateYield(_loop(), "t0", 11);
2301
2372
  case 11:
2302
- _i2++;
2303
- _context6.next = 9;
2373
+ _i3++;
2374
+ _context7.next = 9;
2304
2375
  break;
2305
2376
  case 14:
2306
2377
  // For all updated subscribers: set new module data and emit change
2307
- for (_i3 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i3 < _Array$from2.length; _i3++) {
2308
- _Array$from2$_i = _slicedToArray(_Array$from2[_i3], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2378
+ for (_i4 = 0, _Array$from2 = Array.from(updatedSubscriberIds.entries()); _i4 < _Array$from2.length; _i4++) {
2379
+ _Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), updatedSubscriberId = _Array$from2$_i[0], _moduleIds = _Array$from2$_i[1];
2309
2380
  subscriberModules = Object.fromEntries(_moduleIds.flatMap(function (moduleId) {
2310
2381
  var source = data.value.modules[moduleId].source;
2311
2382
  if (!source) {
@@ -2316,7 +2387,7 @@ var ValStore = /*#__PURE__*/function () {
2316
2387
  this.subscribers.set(updatedSubscriberId, subscriberModules);
2317
2388
  this.emitChange(updatedSubscriberId);
2318
2389
  }
2319
- return _context6.abrupt("return", result.ok(moduleIds));
2390
+ return _context7.abrupt("return", result.ok(moduleIds));
2320
2391
  case 18:
2321
2392
  msg = "Failed to fetch content. ";
2322
2393
  if (data.error.statusCode === 401) {
@@ -2324,7 +2395,7 @@ var ValStore = /*#__PURE__*/function () {
2324
2395
  } else {
2325
2396
  msg += "Get a developer to verify that Val is correctly setup.";
2326
2397
  }
2327
- return _context6.abrupt("return", result.err({
2398
+ return _context7.abrupt("return", result.err({
2328
2399
  message: msg,
2329
2400
  details: {
2330
2401
  fetchError: data.error
@@ -2332,9 +2403,9 @@ var ValStore = /*#__PURE__*/function () {
2332
2403
  }));
2333
2404
  case 21:
2334
2405
  case "end":
2335
- return _context6.stop();
2406
+ return _context7.stop();
2336
2407
  }
2337
- }, _callee5, this);
2408
+ }, _callee6, this);
2338
2409
  }));
2339
2410
  function updateTree(_x5) {
2340
2411
  return _updateTree.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.60.18",
3
+ "version": "0.60.20",
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.60.18",
32
+ "@valbuild/core": "~0.60.20",
33
33
  "marked": "^9.0.3",
34
34
  "zod": "^3.22.4"
35
35
  },