@valbuild/shared 0.59.0 → 0.60.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.
@@ -19,6 +19,7 @@ export declare class ValStore {
19
19
  }>, PatchError | {
20
20
  message: string;
21
21
  }>>;
22
+ private emitEvent;
22
23
  update(moduleIds: ModuleId[]): Promise<void>;
23
24
  reset(): Promise<result.Result<ModuleId[], {
24
25
  message: string;
@@ -29,15 +30,7 @@ export declare class ValStore {
29
30
  };
30
31
  };
31
32
  }>>;
32
- updateTree(treePath?: string): Promise<result.Result<ModuleId[], {
33
- message: string;
34
- details: {
35
- fetchError: {
36
- message: string;
37
- statusCode?: number;
38
- };
39
- };
40
- }>>;
33
+ private updateTree;
41
34
  subscribe: (moduleIds: ModuleId[]) => (listener: () => void) => () => void;
42
35
  private emitChange;
43
36
  getSnapshot: (moduleIds: ModuleId[]) => () => Record<ModuleId, Json> | undefined;
@@ -2174,10 +2174,11 @@ var ValStore = /*#__PURE__*/function () {
2174
2174
  patchRes = patch.applyPatch(currentSource, ops, patch$1.filter(core.Internal.notFileOp) // we cannot apply file ops here
2175
2175
  );
2176
2176
  if (!fp.result.isOk(patchRes)) {
2177
- _context2.next = 34;
2177
+ _context2.next = 35;
2178
2178
  break;
2179
2179
  }
2180
2180
  this.drafts[moduleId] = patchRes.value;
2181
+ this.emitEvent(moduleId, patchRes.value);
2181
2182
  for (_i = 0, _Array$from = Array.from(this.subscribers.entries()); _i < _Array$from.length; _i++) {
2182
2183
  _Array$from$_i = _slicedToArray(_Array$from[_i], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
2183
2184
  if (subscriberModules[moduleId]) {
@@ -2186,10 +2187,10 @@ var ValStore = /*#__PURE__*/function () {
2186
2187
  }
2187
2188
  }
2188
2189
  return _context2.abrupt("return", res);
2189
- case 34:
2190
+ case 35:
2190
2191
  console.error("Val: failed to apply patch", patchRes.error);
2191
2192
  return _context2.abrupt("return", patchRes);
2192
- case 36:
2193
+ case 37:
2193
2194
  case "end":
2194
2195
  return _context2.stop();
2195
2196
  }
@@ -2200,6 +2201,18 @@ var ValStore = /*#__PURE__*/function () {
2200
2201
  }
2201
2202
  return applyPatch;
2202
2203
  }()
2204
+ }, {
2205
+ key: "emitEvent",
2206
+ value: function emitEvent(moduleId, source) {
2207
+ var event = new CustomEvent("val-event", {
2208
+ detail: {
2209
+ type: "module-update",
2210
+ moduleId: moduleId,
2211
+ source: source
2212
+ }
2213
+ });
2214
+ window.dispatchEvent(event);
2215
+ }
2203
2216
  }, {
2204
2217
  key: "update",
2205
2218
  value: function () {
@@ -2246,6 +2259,7 @@ var ValStore = /*#__PURE__*/function () {
2246
2259
  key: "updateTree",
2247
2260
  value: function () {
2248
2261
  var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2262
+ var _this3 = this;
2249
2263
  var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2250
2264
  return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2251
2265
  while (1) switch (_context6.prev = _context6.next) {
@@ -2274,6 +2288,7 @@ var ValStore = /*#__PURE__*/function () {
2274
2288
  moduleIds.push(moduleId);
2275
2289
  source = data.value.modules[moduleId].source;
2276
2290
  if (typeof source !== "undefined") {
2291
+ _this3.emitEvent(moduleId, source);
2277
2292
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2278
2293
  return subscriberId.includes(moduleId);
2279
2294
  } // NOTE: dependent on
@@ -2174,10 +2174,11 @@ var ValStore = /*#__PURE__*/function () {
2174
2174
  patchRes = patch.applyPatch(currentSource, ops, patch$1.filter(core.Internal.notFileOp) // we cannot apply file ops here
2175
2175
  );
2176
2176
  if (!fp.result.isOk(patchRes)) {
2177
- _context2.next = 34;
2177
+ _context2.next = 35;
2178
2178
  break;
2179
2179
  }
2180
2180
  this.drafts[moduleId] = patchRes.value;
2181
+ this.emitEvent(moduleId, patchRes.value);
2181
2182
  for (_i = 0, _Array$from = Array.from(this.subscribers.entries()); _i < _Array$from.length; _i++) {
2182
2183
  _Array$from$_i = _slicedToArray(_Array$from[_i], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
2183
2184
  if (subscriberModules[moduleId]) {
@@ -2186,10 +2187,10 @@ var ValStore = /*#__PURE__*/function () {
2186
2187
  }
2187
2188
  }
2188
2189
  return _context2.abrupt("return", res);
2189
- case 34:
2190
+ case 35:
2190
2191
  console.error("Val: failed to apply patch", patchRes.error);
2191
2192
  return _context2.abrupt("return", patchRes);
2192
- case 36:
2193
+ case 37:
2193
2194
  case "end":
2194
2195
  return _context2.stop();
2195
2196
  }
@@ -2200,6 +2201,18 @@ var ValStore = /*#__PURE__*/function () {
2200
2201
  }
2201
2202
  return applyPatch;
2202
2203
  }()
2204
+ }, {
2205
+ key: "emitEvent",
2206
+ value: function emitEvent(moduleId, source) {
2207
+ var event = new CustomEvent("val-event", {
2208
+ detail: {
2209
+ type: "module-update",
2210
+ moduleId: moduleId,
2211
+ source: source
2212
+ }
2213
+ });
2214
+ window.dispatchEvent(event);
2215
+ }
2203
2216
  }, {
2204
2217
  key: "update",
2205
2218
  value: function () {
@@ -2246,6 +2259,7 @@ var ValStore = /*#__PURE__*/function () {
2246
2259
  key: "updateTree",
2247
2260
  value: function () {
2248
2261
  var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2262
+ var _this3 = this;
2249
2263
  var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2250
2264
  return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2251
2265
  while (1) switch (_context6.prev = _context6.next) {
@@ -2274,6 +2288,7 @@ var ValStore = /*#__PURE__*/function () {
2274
2288
  moduleIds.push(moduleId);
2275
2289
  source = data.value.modules[moduleId].source;
2276
2290
  if (typeof source !== "undefined") {
2291
+ _this3.emitEvent(moduleId, source);
2277
2292
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2278
2293
  return subscriberId.includes(moduleId);
2279
2294
  } // NOTE: dependent on
@@ -2150,10 +2150,11 @@ var ValStore = /*#__PURE__*/function () {
2150
2150
  patchRes = applyPatch(currentSource, ops, patch.filter(Internal.notFileOp) // we cannot apply file ops here
2151
2151
  );
2152
2152
  if (!result.isOk(patchRes)) {
2153
- _context2.next = 34;
2153
+ _context2.next = 35;
2154
2154
  break;
2155
2155
  }
2156
2156
  this.drafts[moduleId] = patchRes.value;
2157
+ this.emitEvent(moduleId, patchRes.value);
2157
2158
  for (_i = 0, _Array$from = Array.from(this.subscribers.entries()); _i < _Array$from.length; _i++) {
2158
2159
  _Array$from$_i = _slicedToArray(_Array$from[_i], 2), subscriberId = _Array$from$_i[0], subscriberModules = _Array$from$_i[1];
2159
2160
  if (subscriberModules[moduleId]) {
@@ -2162,10 +2163,10 @@ var ValStore = /*#__PURE__*/function () {
2162
2163
  }
2163
2164
  }
2164
2165
  return _context2.abrupt("return", res);
2165
- case 34:
2166
+ case 35:
2166
2167
  console.error("Val: failed to apply patch", patchRes.error);
2167
2168
  return _context2.abrupt("return", patchRes);
2168
- case 36:
2169
+ case 37:
2169
2170
  case "end":
2170
2171
  return _context2.stop();
2171
2172
  }
@@ -2176,6 +2177,18 @@ var ValStore = /*#__PURE__*/function () {
2176
2177
  }
2177
2178
  return applyPatch$1;
2178
2179
  }()
2180
+ }, {
2181
+ key: "emitEvent",
2182
+ value: function emitEvent(moduleId, source) {
2183
+ var event = new CustomEvent("val-event", {
2184
+ detail: {
2185
+ type: "module-update",
2186
+ moduleId: moduleId,
2187
+ source: source
2188
+ }
2189
+ });
2190
+ window.dispatchEvent(event);
2191
+ }
2179
2192
  }, {
2180
2193
  key: "update",
2181
2194
  value: function () {
@@ -2222,6 +2235,7 @@ var ValStore = /*#__PURE__*/function () {
2222
2235
  key: "updateTree",
2223
2236
  value: function () {
2224
2237
  var _updateTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(treePath) {
2238
+ var _this3 = this;
2225
2239
  var data, moduleIds, updatedSubscriberIds, subscriberIds, _loop, _i2, _arr, _i3, _Array$from2, _Array$from2$_i, updatedSubscriberId, _moduleIds, subscriberModules, msg;
2226
2240
  return _regeneratorRuntime().wrap(function _callee5$(_context6) {
2227
2241
  while (1) switch (_context6.prev = _context6.next) {
@@ -2250,6 +2264,7 @@ var ValStore = /*#__PURE__*/function () {
2250
2264
  moduleIds.push(moduleId);
2251
2265
  source = data.value.modules[moduleId].source;
2252
2266
  if (typeof source !== "undefined") {
2267
+ _this3.emitEvent(moduleId, source);
2253
2268
  updatedSubscriberId = subscriberIds.find(function (subscriberId) {
2254
2269
  return subscriberId.includes(moduleId);
2255
2270
  } // NOTE: dependent on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.59.0",
3
+ "version": "0.60.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.59.0",
32
+ "@valbuild/core": "~0.60.0",
33
33
  "marked": "^9.0.3",
34
34
  "zod": "^3.22.4"
35
35
  },