@modern-js/runtime-utils 2.67.2 → 2.67.4

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.
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var deferreds_exports = {};
20
+ __export(deferreds_exports, {
21
+ AbortedDeferredError: () => AbortedDeferredError,
22
+ DeferredData: () => DeferredData,
23
+ activeDeferreds: () => activeDeferreds,
24
+ invariant: () => invariant
25
+ });
26
+ module.exports = __toCommonJS(deferreds_exports);
27
+ function invariant(value, message) {
28
+ if (value === false || value === null || typeof value === "undefined") {
29
+ throw new Error(message);
30
+ }
31
+ }
32
+ class AbortedDeferredError extends Error {
33
+ }
34
+ function isTrackedPromise(value) {
35
+ return value instanceof Promise && value._tracked === true;
36
+ }
37
+ function unwrapTrackedPromise(value) {
38
+ if (!isTrackedPromise(value)) {
39
+ return value;
40
+ }
41
+ if (value._error) {
42
+ throw value._error;
43
+ }
44
+ return value._data;
45
+ }
46
+ class DeferredData {
47
+ trackPromise(key, value) {
48
+ if (!(value instanceof Promise)) {
49
+ return value;
50
+ }
51
+ this.deferredKeys.push(key);
52
+ this.pendingKeysSet.add(key);
53
+ const promise = Promise.race([
54
+ value,
55
+ this.abortPromise
56
+ ]).then((data) => this.onSettle(promise, key, void 0, data), (error) => this.onSettle(promise, key, error));
57
+ promise.catch(() => {
58
+ });
59
+ Object.defineProperty(promise, "_tracked", {
60
+ get: () => true
61
+ });
62
+ return promise;
63
+ }
64
+ onSettle(promise, key, error, data) {
65
+ if (this.controller.signal.aborted && error instanceof AbortedDeferredError) {
66
+ this.unlistenAbortSignal();
67
+ Object.defineProperty(promise, "_error", {
68
+ get: () => error
69
+ });
70
+ return Promise.reject(error);
71
+ }
72
+ this.pendingKeysSet.delete(key);
73
+ if (this.done) {
74
+ this.unlistenAbortSignal();
75
+ }
76
+ if (error === void 0 && data === void 0) {
77
+ const undefinedError = new Error(`Deferred data for key "${key}" resolved/rejected with \`undefined\`, you must resolve/reject with a value or \`null\`.`);
78
+ Object.defineProperty(promise, "_error", {
79
+ get: () => undefinedError
80
+ });
81
+ this.emit(false, key);
82
+ return Promise.reject(undefinedError);
83
+ }
84
+ if (data === void 0) {
85
+ Object.defineProperty(promise, "_error", {
86
+ get: () => error
87
+ });
88
+ this.emit(false, key);
89
+ return Promise.reject(error);
90
+ }
91
+ Object.defineProperty(promise, "_data", {
92
+ get: () => data
93
+ });
94
+ this.emit(false, key);
95
+ return data;
96
+ }
97
+ emit(aborted, settledKey) {
98
+ this.subscribers.forEach((subscriber) => subscriber(aborted, settledKey));
99
+ }
100
+ subscribe(fn) {
101
+ this.subscribers.add(fn);
102
+ return () => this.subscribers.delete(fn);
103
+ }
104
+ cancel() {
105
+ this.controller.abort();
106
+ this.pendingKeysSet.forEach((v, k) => this.pendingKeysSet.delete(k));
107
+ this.emit(true);
108
+ }
109
+ async resolveData(signal) {
110
+ let aborted = false;
111
+ if (!this.done) {
112
+ const onAbort = () => this.cancel();
113
+ signal.addEventListener("abort", onAbort);
114
+ aborted = await new Promise((resolve) => {
115
+ this.subscribe((aborted2) => {
116
+ signal.removeEventListener("abort", onAbort);
117
+ if (aborted2 || this.done) {
118
+ resolve(aborted2);
119
+ }
120
+ });
121
+ });
122
+ }
123
+ return aborted;
124
+ }
125
+ get done() {
126
+ return this.pendingKeysSet.size === 0;
127
+ }
128
+ get unwrappedData() {
129
+ invariant(this.data !== null && this.done, "Can only unwrap data on initialized and settled deferreds");
130
+ return Object.entries(this.data).reduce((acc, [key, value]) => Object.assign(acc, {
131
+ [key]: unwrapTrackedPromise(value)
132
+ }), {});
133
+ }
134
+ get pendingKeys() {
135
+ return Array.from(this.pendingKeysSet);
136
+ }
137
+ constructor(data, responseInit) {
138
+ this.pendingKeysSet = /* @__PURE__ */ new Set();
139
+ this.subscribers = /* @__PURE__ */ new Set();
140
+ this.__modern_deferred = true;
141
+ this.deferredKeys = [];
142
+ invariant(data && typeof data === "object" && !Array.isArray(data), "defer() only accepts plain objects");
143
+ let reject;
144
+ this.abortPromise = new Promise((_, r) => reject = r);
145
+ this.controller = new AbortController();
146
+ const onAbort = () => reject(new AbortedDeferredError("Deferred data aborted"));
147
+ this.unlistenAbortSignal = () => this.controller.signal.removeEventListener("abort", onAbort);
148
+ this.controller.signal.addEventListener("abort", onAbort);
149
+ this.data = Object.entries(data).reduce((acc, [key, value]) => Object.assign(acc, {
150
+ [key]: this.trackPromise(key, value)
151
+ }), {});
152
+ if (this.done) {
153
+ this.unlistenAbortSignal();
154
+ }
155
+ this.init = responseInit;
156
+ }
157
+ }
158
+ const activeDeferreds = /* @__PURE__ */ new Map();
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ AbortedDeferredError,
162
+ DeferredData,
163
+ activeDeferreds,
164
+ invariant
165
+ });
@@ -16,7 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var browser_exports = {};
17
17
  module.exports = __toCommonJS(browser_exports);
18
18
  __reExport(browser_exports, require("./nestedRoutes"), module.exports);
19
+ __reExport(browser_exports, require("./deferreds"), module.exports);
19
20
  // Annotate the CommonJS export names for ESM import in node:
20
21
  0 && (module.exports = {
21
- ...require("./nestedRoutes")
22
+ ...require("./nestedRoutes"),
23
+ ...require("./deferreds")
22
24
  });
@@ -28,6 +28,10 @@ var import_react = require("react");
28
28
  var import_react_router_dom = require("react-router-dom");
29
29
  var import_time = require("../time");
30
30
  var import_async_storage = require("../universal/async_storage");
31
+ var import_deferreds = require("./deferreds");
32
+ const privateDefer = (data) => {
33
+ return new import_deferreds.DeferredData(data);
34
+ };
31
35
  const transformNestedRoutes = (routes) => {
32
36
  const routeElements = [];
33
37
  for (const route of routes) {
@@ -110,6 +114,9 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
110
114
  }, id);
111
115
  return routeElement;
112
116
  };
117
+ function isPlainObject(value) {
118
+ return value != null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
119
+ }
113
120
  function createLoader(route) {
114
121
  const { loader } = route;
115
122
  if (loader) {
@@ -119,11 +126,25 @@ function createLoader(route) {
119
126
  }
120
127
  const end = (0, import_time.time)();
121
128
  const res = await loader(args);
129
+ const isRouterV7 = process.env._MODERN_ROUTER_VERSION === "v7";
130
+ if (isRouterV7) {
131
+ let activeDeferreds = null;
132
+ if (typeof document === "undefined") {
133
+ var _getAsyncLocalStorage_useContext, _getAsyncLocalStorage;
134
+ activeDeferreds = (_getAsyncLocalStorage = (0, import_async_storage.getAsyncLocalStorage)()) === null || _getAsyncLocalStorage === void 0 ? void 0 : (_getAsyncLocalStorage_useContext = _getAsyncLocalStorage.useContext()) === null || _getAsyncLocalStorage_useContext === void 0 ? void 0 : _getAsyncLocalStorage_useContext.activeDeferreds;
135
+ } else {
136
+ activeDeferreds = import_deferreds.activeDeferreds;
137
+ }
138
+ if (isPlainObject(res)) {
139
+ const deferredData = privateDefer(res);
140
+ activeDeferreds.set(route.id, deferredData);
141
+ }
142
+ }
122
143
  const cost = end();
123
144
  if (typeof document === "undefined") {
124
- var _storage_useContext_monitors;
145
+ var _route_id, _storage_useContext_monitors;
125
146
  const storage = (0, import_async_storage.getAsyncLocalStorage)();
126
- storage === null || storage === void 0 ? void 0 : (_storage_useContext_monitors = storage.useContext().monitors) === null || _storage_useContext_monitors === void 0 ? void 0 : _storage_useContext_monitors.timing(`${import_constants.LOADER_REPORTER_NAME}-${route.id}`, cost);
147
+ storage === null || storage === void 0 ? void 0 : (_storage_useContext_monitors = storage.useContext().monitors) === null || _storage_useContext_monitors === void 0 ? void 0 : _storage_useContext_monitors.timing(`${import_constants.LOADER_REPORTER_NAME}-${(_route_id = route.id) === null || _route_id === void 0 ? void 0 : _route_id.replace(/\//g, "_")}`, cost);
127
148
  }
128
149
  return res;
129
150
  };
@@ -21,9 +21,20 @@ __export(async_storage_exports, {
21
21
  getAsyncLocalStorage: () => getAsyncLocalStorage
22
22
  });
23
23
  module.exports = __toCommonJS(async_storage_exports);
24
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
24
25
  const getAsyncLocalStorage = () => {
25
- console.error("You should not get async storage in browser");
26
- return null;
26
+ if (isBrowser) {
27
+ console.error("You should not get async storage in browser");
28
+ return null;
29
+ } else {
30
+ try {
31
+ const serverStorage = require("./async_storage.server");
32
+ return serverStorage.getAsyncLocalStorage();
33
+ } catch (err) {
34
+ console.error("Failed to load server async storage", err);
35
+ return null;
36
+ }
37
+ }
27
38
  };
28
39
  // Annotate the CommonJS export names for ESM import in node:
29
40
  0 && (module.exports = {
@@ -49,14 +49,14 @@ let lruCache;
49
49
  let cacheConfig = {
50
50
  maxSize: CacheSize.GB
51
51
  };
52
- const tagFnMap = /* @__PURE__ */ new Map();
53
- function addTagFnRelation(tag, fn) {
54
- let fns = tagFnMap.get(tag);
55
- if (!fns) {
56
- fns = /* @__PURE__ */ new Set();
57
- tagFnMap.set(tag, fns);
52
+ const tagKeyMap = /* @__PURE__ */ new Map();
53
+ function addTagKeyRelation(tag, key) {
54
+ let keys = tagKeyMap.get(tag);
55
+ if (!keys) {
56
+ keys = /* @__PURE__ */ new Set();
57
+ tagKeyMap.set(tag, keys);
58
58
  }
59
- fns.add(fn);
59
+ keys.add(key);
60
60
  }
61
61
  function configureCache(config) {
62
62
  cacheConfig = {
@@ -66,8 +66,9 @@ function configureCache(config) {
66
66
  }
67
67
  function getLRUCache() {
68
68
  if (!lruCache) {
69
+ var _cacheConfig_maxSize;
69
70
  lruCache = new import_lru_cache.LRUCache({
70
- maxSize: cacheConfig.maxSize,
71
+ maxSize: (_cacheConfig_maxSize = cacheConfig.maxSize) !== null && _cacheConfig_maxSize !== void 0 ? _cacheConfig_maxSize : CacheSize.GB,
71
72
  sizeCalculation: (value) => {
72
73
  if (!value.size) {
73
74
  return 1;
@@ -125,18 +126,33 @@ function generateKey(args) {
125
126
  });
126
127
  }
127
128
  function cache(fn, options) {
128
- const { tag = "default", maxAge = CacheTime.MINUTE * 5, revalidate = 0 } = options || {};
129
+ const { tag = "default", maxAge = CacheTime.MINUTE * 5, revalidate = 0, customKey, onCache, getKey } = options || {};
129
130
  const store = getLRUCache();
130
131
  const tags = Array.isArray(tag) ? tag : [
131
132
  tag
132
133
  ];
133
- tags.forEach((t) => addTagFnRelation(t, fn));
134
+ const getCacheKey = (args, generatedKey) => {
135
+ return customKey ? customKey({
136
+ params: args,
137
+ fn,
138
+ generatedKey
139
+ }) : fn;
140
+ };
134
141
  return async (...args) => {
135
142
  if (isServer && typeof options === "undefined") {
136
143
  var _storage_useContext;
137
144
  const storage = (0, import_async_storage.getAsyncLocalStorage)();
138
145
  const request = storage === null || storage === void 0 ? void 0 : (_storage_useContext = storage.useContext()) === null || _storage_useContext === void 0 ? void 0 : _storage_useContext.request;
139
146
  if (request) {
147
+ let shouldDisableCaching = false;
148
+ if (cacheConfig.unstable_shouldDisable) {
149
+ shouldDisableCaching = await cacheConfig.unstable_shouldDisable({
150
+ request
151
+ });
152
+ }
153
+ if (shouldDisableCaching) {
154
+ return fn(...args);
155
+ }
140
156
  let requestCache = requestCacheMap.get(request);
141
157
  if (!requestCache) {
142
158
  requestCache = /* @__PURE__ */ new Map();
@@ -162,30 +178,61 @@ function cache(fn, options) {
162
178
  }
163
179
  }
164
180
  } else if (typeof options !== "undefined") {
165
- let tagCache = store.get(fn);
166
- if (!tagCache) {
167
- tagCache = /* @__PURE__ */ new Map();
168
- }
169
- const key = generateKey(args);
170
- const cached = tagCache.get(key);
181
+ const genKey = getKey ? getKey(...args) : generateKey(args);
171
182
  const now = Date.now();
172
- if (cached) {
183
+ const cacheKey = getCacheKey(args, genKey);
184
+ const finalKey = typeof cacheKey === "function" ? genKey : cacheKey;
185
+ tags.forEach((t) => addTagKeyRelation(t, cacheKey));
186
+ let cacheStore = store.get(cacheKey);
187
+ if (!cacheStore) {
188
+ cacheStore = /* @__PURE__ */ new Map();
189
+ }
190
+ const storeKey = customKey && typeof cacheKey === "symbol" ? "symbol-key" : genKey;
191
+ let shouldDisableCaching = false;
192
+ if (isServer && cacheConfig.unstable_shouldDisable) {
193
+ var _storage_useContext1;
194
+ const storage = (0, import_async_storage.getAsyncLocalStorage)();
195
+ const request = storage === null || storage === void 0 ? void 0 : (_storage_useContext1 = storage.useContext()) === null || _storage_useContext1 === void 0 ? void 0 : _storage_useContext1.request;
196
+ if (request) {
197
+ shouldDisableCaching = await cacheConfig.unstable_shouldDisable({
198
+ request
199
+ });
200
+ }
201
+ }
202
+ const cached = cacheStore.get(storeKey);
203
+ if (cached && !shouldDisableCaching) {
173
204
  const age = now - cached.timestamp;
174
205
  if (age < maxAge) {
206
+ if (onCache) {
207
+ onCache({
208
+ status: "hit",
209
+ key: finalKey,
210
+ params: args,
211
+ result: cached.data
212
+ });
213
+ }
175
214
  return cached.data;
176
215
  }
177
216
  if (revalidate > 0 && age < maxAge + revalidate) {
217
+ if (onCache) {
218
+ onCache({
219
+ status: "stale",
220
+ key: finalKey,
221
+ params: args,
222
+ result: cached.data
223
+ });
224
+ }
178
225
  if (!cached.isRevalidating) {
179
226
  cached.isRevalidating = true;
180
227
  Promise.resolve().then(async () => {
181
228
  try {
182
229
  const newData = await fn(...args);
183
- tagCache.set(key, {
230
+ cacheStore.set(storeKey, {
184
231
  data: newData,
185
232
  timestamp: Date.now(),
186
233
  isRevalidating: false
187
234
  });
188
- store.set(fn, tagCache);
235
+ store.set(cacheKey, cacheStore);
189
236
  } catch (error) {
190
237
  cached.isRevalidating = false;
191
238
  if (isServer) {
@@ -202,12 +249,22 @@ function cache(fn, options) {
202
249
  }
203
250
  }
204
251
  const data = await fn(...args);
205
- tagCache.set(key, {
206
- data,
207
- timestamp: now,
208
- isRevalidating: false
209
- });
210
- store.set(fn, tagCache);
252
+ if (!shouldDisableCaching) {
253
+ cacheStore.set(storeKey, {
254
+ data,
255
+ timestamp: now,
256
+ isRevalidating: false
257
+ });
258
+ store.set(cacheKey, cacheStore);
259
+ }
260
+ if (onCache) {
261
+ onCache({
262
+ status: "miss",
263
+ key: finalKey,
264
+ params: args,
265
+ result: data
266
+ });
267
+ }
211
268
  return data;
212
269
  } else {
213
270
  console.warn("The cache function will not work because it runs on the browser and there are no options are provided.");
@@ -227,17 +284,17 @@ function withRequestCache(handler) {
227
284
  };
228
285
  }
229
286
  function revalidateTag(tag) {
230
- const fns = tagFnMap.get(tag);
231
- if (fns) {
232
- fns.forEach((fn) => {
233
- lruCache === null || lruCache === void 0 ? void 0 : lruCache.delete(fn);
287
+ const keys = tagKeyMap.get(tag);
288
+ if (keys) {
289
+ keys.forEach((key) => {
290
+ lruCache === null || lruCache === void 0 ? void 0 : lruCache.delete(key);
234
291
  });
235
292
  }
236
293
  }
237
294
  function clearStore() {
238
295
  lruCache === null || lruCache === void 0 ? void 0 : lruCache.clear();
239
296
  lruCache = void 0;
240
- tagFnMap.clear();
297
+ tagKeyMap.clear();
241
298
  }
242
299
  // Annotate the CommonJS export names for ESM import in node:
243
300
  0 && (module.exports = {
@@ -0,0 +1,227 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _call_super } from "@swc/helpers/_/_call_super";
3
+ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
4
+ import { _ as _create_class } from "@swc/helpers/_/_create_class";
5
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
6
+ import { _ as _inherits } from "@swc/helpers/_/_inherits";
7
+ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
8
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
9
+ import { _ as _type_of } from "@swc/helpers/_/_type_of";
10
+ import { _ as _wrap_native_super } from "@swc/helpers/_/_wrap_native_super";
11
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
12
+ function invariant(value, message) {
13
+ if (value === false || value === null || typeof value === "undefined") {
14
+ throw new Error(message);
15
+ }
16
+ }
17
+ var AbortedDeferredError = /* @__PURE__ */ function(Error1) {
18
+ "use strict";
19
+ _inherits(AbortedDeferredError2, Error1);
20
+ function AbortedDeferredError2() {
21
+ _class_call_check(this, AbortedDeferredError2);
22
+ return _call_super(this, AbortedDeferredError2, arguments);
23
+ }
24
+ return AbortedDeferredError2;
25
+ }(_wrap_native_super(Error));
26
+ function isTrackedPromise(value) {
27
+ return _instanceof(value, Promise) && value._tracked === true;
28
+ }
29
+ function unwrapTrackedPromise(value) {
30
+ if (!isTrackedPromise(value)) {
31
+ return value;
32
+ }
33
+ if (value._error) {
34
+ throw value._error;
35
+ }
36
+ return value._data;
37
+ }
38
+ var DeferredData = /* @__PURE__ */ function() {
39
+ "use strict";
40
+ function DeferredData2(data, responseInit) {
41
+ var _this = this;
42
+ _class_call_check(this, DeferredData2);
43
+ this.pendingKeysSet = /* @__PURE__ */ new Set();
44
+ this.subscribers = /* @__PURE__ */ new Set();
45
+ this.__modern_deferred = true;
46
+ this.deferredKeys = [];
47
+ invariant(data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object" && !Array.isArray(data), "defer() only accepts plain objects");
48
+ var reject;
49
+ this.abortPromise = new Promise(function(_, r) {
50
+ return reject = r;
51
+ });
52
+ this.controller = new AbortController();
53
+ var onAbort = function() {
54
+ return reject(new AbortedDeferredError("Deferred data aborted"));
55
+ };
56
+ this.unlistenAbortSignal = function() {
57
+ return _this.controller.signal.removeEventListener("abort", onAbort);
58
+ };
59
+ this.controller.signal.addEventListener("abort", onAbort);
60
+ this.data = Object.entries(data).reduce(function(acc, param) {
61
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
62
+ return Object.assign(acc, _define_property({}, key, _this.trackPromise(key, value)));
63
+ }, {});
64
+ if (this.done) {
65
+ this.unlistenAbortSignal();
66
+ }
67
+ this.init = responseInit;
68
+ }
69
+ var _proto = DeferredData2.prototype;
70
+ _proto.trackPromise = function trackPromise(key, value) {
71
+ var _this = this;
72
+ if (!_instanceof(value, Promise)) {
73
+ return value;
74
+ }
75
+ this.deferredKeys.push(key);
76
+ this.pendingKeysSet.add(key);
77
+ var promise = Promise.race([
78
+ value,
79
+ this.abortPromise
80
+ ]).then(function(data) {
81
+ return _this.onSettle(promise, key, void 0, data);
82
+ }, function(error) {
83
+ return _this.onSettle(promise, key, error);
84
+ });
85
+ promise.catch(function() {
86
+ });
87
+ Object.defineProperty(promise, "_tracked", {
88
+ get: function() {
89
+ return true;
90
+ }
91
+ });
92
+ return promise;
93
+ };
94
+ _proto.onSettle = function onSettle(promise, key, error, data) {
95
+ if (this.controller.signal.aborted && _instanceof(error, AbortedDeferredError)) {
96
+ this.unlistenAbortSignal();
97
+ Object.defineProperty(promise, "_error", {
98
+ get: function() {
99
+ return error;
100
+ }
101
+ });
102
+ return Promise.reject(error);
103
+ }
104
+ this.pendingKeysSet.delete(key);
105
+ if (this.done) {
106
+ this.unlistenAbortSignal();
107
+ }
108
+ if (error === void 0 && data === void 0) {
109
+ var undefinedError = new Error('Deferred data for key "'.concat(key, '" resolved/rejected with `undefined`, you must resolve/reject with a value or `null`.'));
110
+ Object.defineProperty(promise, "_error", {
111
+ get: function() {
112
+ return undefinedError;
113
+ }
114
+ });
115
+ this.emit(false, key);
116
+ return Promise.reject(undefinedError);
117
+ }
118
+ if (data === void 0) {
119
+ Object.defineProperty(promise, "_error", {
120
+ get: function() {
121
+ return error;
122
+ }
123
+ });
124
+ this.emit(false, key);
125
+ return Promise.reject(error);
126
+ }
127
+ Object.defineProperty(promise, "_data", {
128
+ get: function() {
129
+ return data;
130
+ }
131
+ });
132
+ this.emit(false, key);
133
+ return data;
134
+ };
135
+ _proto.emit = function emit(aborted, settledKey) {
136
+ this.subscribers.forEach(function(subscriber) {
137
+ return subscriber(aborted, settledKey);
138
+ });
139
+ };
140
+ _proto.subscribe = function subscribe(fn) {
141
+ var _this = this;
142
+ this.subscribers.add(fn);
143
+ return function() {
144
+ return _this.subscribers.delete(fn);
145
+ };
146
+ };
147
+ _proto.cancel = function cancel() {
148
+ var _this = this;
149
+ this.controller.abort();
150
+ this.pendingKeysSet.forEach(function(v, k) {
151
+ return _this.pendingKeysSet.delete(k);
152
+ });
153
+ this.emit(true);
154
+ };
155
+ _proto.resolveData = function resolveData(signal) {
156
+ var _this = this;
157
+ return _async_to_generator(function() {
158
+ var aborted, onAbort;
159
+ return _ts_generator(this, function(_state) {
160
+ switch (_state.label) {
161
+ case 0:
162
+ aborted = false;
163
+ if (!!_this.done)
164
+ return [
165
+ 3,
166
+ 2
167
+ ];
168
+ onAbort = function() {
169
+ return _this.cancel();
170
+ };
171
+ signal.addEventListener("abort", onAbort);
172
+ return [
173
+ 4,
174
+ new Promise(function(resolve) {
175
+ _this.subscribe(function(aborted2) {
176
+ signal.removeEventListener("abort", onAbort);
177
+ if (aborted2 || _this.done) {
178
+ resolve(aborted2);
179
+ }
180
+ });
181
+ })
182
+ ];
183
+ case 1:
184
+ aborted = _state.sent();
185
+ _state.label = 2;
186
+ case 2:
187
+ return [
188
+ 2,
189
+ aborted
190
+ ];
191
+ }
192
+ });
193
+ })();
194
+ };
195
+ _create_class(DeferredData2, [
196
+ {
197
+ key: "done",
198
+ get: function get() {
199
+ return this.pendingKeysSet.size === 0;
200
+ }
201
+ },
202
+ {
203
+ key: "unwrappedData",
204
+ get: function get() {
205
+ invariant(this.data !== null && this.done, "Can only unwrap data on initialized and settled deferreds");
206
+ return Object.entries(this.data).reduce(function(acc, param) {
207
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
208
+ return Object.assign(acc, _define_property({}, key, unwrapTrackedPromise(value)));
209
+ }, {});
210
+ }
211
+ },
212
+ {
213
+ key: "pendingKeys",
214
+ get: function get() {
215
+ return Array.from(this.pendingKeysSet);
216
+ }
217
+ }
218
+ ]);
219
+ return DeferredData2;
220
+ }();
221
+ var activeDeferreds = /* @__PURE__ */ new Map();
222
+ export {
223
+ AbortedDeferredError,
224
+ DeferredData,
225
+ activeDeferreds,
226
+ invariant
227
+ };
@@ -1 +1,2 @@
1
1
  export * from "./nestedRoutes";
2
+ export * from "./deferreds";