@modern-js/runtime-utils 2.69.5 → 3.0.0-alpha.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.
Files changed (135) hide show
  1. package/dist/cjs/browser/deferreds.js +141 -145
  2. package/dist/cjs/browser/index.js +62 -21
  3. package/dist/cjs/browser/nestedRoutes.js +121 -147
  4. package/dist/cjs/merge.js +51 -44
  5. package/dist/cjs/node/fileReader.js +88 -97
  6. package/dist/cjs/node/index.js +87 -33
  7. package/dist/cjs/node/loaderContext/createLoaderCtx.js +43 -36
  8. package/dist/cjs/node/loaderContext/createRequestCtx.js +43 -41
  9. package/dist/cjs/node/loaderContext/index.js +38 -29
  10. package/dist/cjs/node/serialize.js +46 -40
  11. package/dist/cjs/node/storer/container.js +62 -58
  12. package/dist/cjs/node/storer/index.js +39 -31
  13. package/dist/cjs/node/storer/storage.js +82 -92
  14. package/dist/cjs/node/stream.js +89 -91
  15. package/dist/cjs/parsed.js +40 -38
  16. package/dist/cjs/router.js +88 -19
  17. package/dist/cjs/rsc.js +58 -0
  18. package/dist/cjs/server/index.js +55 -19
  19. package/dist/cjs/server/nestedRoutes.js +43 -39
  20. package/dist/cjs/time.js +53 -47
  21. package/dist/cjs/universal/async_storage.js +53 -37
  22. package/dist/cjs/universal/async_storage.server.js +63 -74
  23. package/dist/cjs/universal/cache.js +330 -381
  24. package/dist/cjs/universal/request.js +73 -65
  25. package/dist/cjs/url.js +33 -28
  26. package/dist/esm/browser/deferreds.mjs +118 -0
  27. package/dist/esm/browser/nestedRoutes.mjs +104 -0
  28. package/dist/esm/merge.mjs +26 -0
  29. package/dist/esm/node/fileReader.mjs +47 -0
  30. package/dist/{esm-node/node/index.js → esm/node/index.mjs} +2 -5
  31. package/dist/esm/node/loaderContext/createLoaderCtx.mjs +14 -0
  32. package/dist/esm/node/loaderContext/createRequestCtx.mjs +16 -0
  33. package/dist/{esm-node/node/loaderContext/index.js → esm/node/loaderContext/index.mjs} +1 -4
  34. package/dist/esm/node/serialize.mjs +5 -0
  35. package/dist/esm/node/storer/container.mjs +38 -0
  36. package/dist/{esm-node/node/storer/index.js → esm/node/storer/index.mjs} +2 -6
  37. package/dist/esm/node/storer/storage.mjs +53 -0
  38. package/dist/esm/node/stream.mjs +68 -0
  39. package/dist/esm/parsed.mjs +12 -0
  40. package/dist/esm/router.mjs +18 -0
  41. package/dist/esm/rsc.mjs +1 -0
  42. package/dist/esm/server/nestedRoutes.mjs +15 -0
  43. package/dist/esm/time.mjs +27 -0
  44. package/dist/esm/universal/async_storage.mjs +7 -0
  45. package/dist/esm/universal/async_storage.server.mjs +32 -0
  46. package/dist/esm/universal/cache.mjs +326 -0
  47. package/dist/esm/universal/request.mjs +40 -0
  48. package/dist/esm/url.mjs +5 -0
  49. package/dist/esm-node/browser/deferreds.mjs +118 -0
  50. package/dist/esm-node/browser/index.mjs +2 -0
  51. package/dist/esm-node/browser/nestedRoutes.mjs +104 -0
  52. package/dist/esm-node/merge.mjs +26 -0
  53. package/dist/esm-node/node/fileReader.mjs +47 -0
  54. package/dist/esm-node/node/index.mjs +5 -0
  55. package/dist/esm-node/node/loaderContext/createLoaderCtx.mjs +14 -0
  56. package/dist/esm-node/node/loaderContext/createRequestCtx.mjs +16 -0
  57. package/dist/esm-node/node/loaderContext/index.mjs +4 -0
  58. package/dist/esm-node/node/serialize.mjs +5 -0
  59. package/dist/esm-node/node/storer/container.mjs +38 -0
  60. package/dist/esm-node/node/storer/index.mjs +7 -0
  61. package/dist/esm-node/node/storer/storage.mjs +53 -0
  62. package/dist/esm-node/node/stream.mjs +68 -0
  63. package/dist/esm-node/parsed.mjs +12 -0
  64. package/dist/esm-node/router.mjs +18 -0
  65. package/dist/esm-node/rsc.mjs +1 -0
  66. package/dist/esm-node/server/index.mjs +1 -0
  67. package/dist/esm-node/server/nestedRoutes.mjs +15 -0
  68. package/dist/esm-node/time.mjs +27 -0
  69. package/dist/esm-node/universal/async_storage.mjs +24 -0
  70. package/dist/esm-node/universal/async_storage.server.mjs +32 -0
  71. package/dist/esm-node/universal/cache.mjs +326 -0
  72. package/dist/esm-node/universal/request.mjs +40 -0
  73. package/dist/esm-node/url.mjs +5 -0
  74. package/dist/types/browser/nestedRoutes.d.ts +2 -1
  75. package/dist/types/node/stream.d.ts +1 -1
  76. package/dist/types/router.d.ts +6 -1
  77. package/dist/types/rsc.d.ts +1 -0
  78. package/dist/types/universal/async_storage.d.ts +1 -1
  79. package/dist/types/universal/async_storage.server.d.ts +1 -1
  80. package/package.json +36 -46
  81. package/rslib.config.mts +27 -0
  82. package/rstest.config.ts +26 -0
  83. package/dist/cjs/node/router.js +0 -22
  84. package/dist/cjs/remixRouter.js +0 -43
  85. package/dist/esm/browser/deferreds.js +0 -227
  86. package/dist/esm/browser/index.js +0 -2
  87. package/dist/esm/browser/nestedRoutes.js +0 -177
  88. package/dist/esm/merge.js +0 -33
  89. package/dist/esm/node/fileReader.js +0 -140
  90. package/dist/esm/node/index.js +0 -8
  91. package/dist/esm/node/loaderContext/createLoaderCtx.js +0 -24
  92. package/dist/esm/node/loaderContext/createRequestCtx.js +0 -24
  93. package/dist/esm/node/loaderContext/index.js +0 -7
  94. package/dist/esm/node/router.js +0 -1
  95. package/dist/esm/node/serialize.js +0 -9
  96. package/dist/esm/node/storer/container.js +0 -94
  97. package/dist/esm/node/storer/index.js +0 -11
  98. package/dist/esm/node/storer/storage.js +0 -135
  99. package/dist/esm/node/stream.js +0 -87
  100. package/dist/esm/parsed.js +0 -20
  101. package/dist/esm/remixRouter.js +0 -7
  102. package/dist/esm/router.js +0 -1
  103. package/dist/esm/server/index.js +0 -1
  104. package/dist/esm/server/nestedRoutes.js +0 -23
  105. package/dist/esm/time.js +0 -32
  106. package/dist/esm/universal/async_storage.js +0 -18
  107. package/dist/esm/universal/async_storage.server.js +0 -43
  108. package/dist/esm/universal/cache.js +0 -1032
  109. package/dist/esm/universal/request.js +0 -51
  110. package/dist/esm/url.js +0 -10
  111. package/dist/esm-node/browser/deferreds.js +0 -138
  112. package/dist/esm-node/browser/nestedRoutes.js +0 -142
  113. package/dist/esm-node/merge.js +0 -29
  114. package/dist/esm-node/node/fileReader.js +0 -68
  115. package/dist/esm-node/node/loaderContext/createLoaderCtx.js +0 -19
  116. package/dist/esm-node/node/loaderContext/createRequestCtx.js +0 -24
  117. package/dist/esm-node/node/router.js +0 -1
  118. package/dist/esm-node/node/serialize.js +0 -9
  119. package/dist/esm-node/node/storer/container.js +0 -44
  120. package/dist/esm-node/node/storer/storage.js +0 -73
  121. package/dist/esm-node/node/stream.js +0 -80
  122. package/dist/esm-node/parsed.js +0 -20
  123. package/dist/esm-node/remixRouter.js +0 -7
  124. package/dist/esm-node/router.js +0 -1
  125. package/dist/esm-node/server/nestedRoutes.js +0 -21
  126. package/dist/esm-node/time.js +0 -31
  127. package/dist/esm-node/universal/async_storage.js +0 -18
  128. package/dist/esm-node/universal/async_storage.server.js +0 -45
  129. package/dist/esm-node/universal/cache.js +0 -401
  130. package/dist/esm-node/universal/request.js +0 -50
  131. package/dist/esm-node/url.js +0 -10
  132. package/dist/types/node/router.d.ts +0 -1
  133. package/dist/types/remixRouter.d.ts +0 -2
  134. /package/dist/{esm-node/browser/index.js → esm/browser/index.mjs} +0 -0
  135. /package/dist/{esm-node/server/index.js → esm/server/index.mjs} +0 -0
@@ -1 +0,0 @@
1
- export * from "react-router-dom/server";
@@ -1,9 +0,0 @@
1
- import serialize from "serialize-javascript";
2
- var serializeJson = function(data) {
3
- return serialize(data, {
4
- isJSON: true
5
- });
6
- };
7
- export {
8
- serializeJson
9
- };
@@ -1,94 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { LRUCache } from "lru-cache";
5
- var MemoryContainer = /* @__PURE__ */ function() {
6
- "use strict";
7
- function MemoryContainer2() {
8
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, max = _ref.max, maxAge = _ref.maxAge;
9
- _class_call_check(this, MemoryContainer2);
10
- this.cache = new LRUCache({
11
- maxSize: (max || 256) * MemoryContainer2.MB,
12
- ttl: maxAge || MemoryContainer2.hour,
13
- sizeCalculation: function(value, key) {
14
- return JSON.stringify(value).length;
15
- }
16
- });
17
- }
18
- var _proto = MemoryContainer2.prototype;
19
- _proto.get = function get(key) {
20
- var _this = this;
21
- return _async_to_generator(function() {
22
- return _ts_generator(this, function(_state) {
23
- return [
24
- 2,
25
- _this.cache.get(key)
26
- ];
27
- });
28
- })();
29
- };
30
- _proto.set = function set(key, value) {
31
- var _this = this;
32
- return _async_to_generator(function() {
33
- return _ts_generator(this, function(_state) {
34
- _this.cache.set(key, value);
35
- return [
36
- 2,
37
- _this
38
- ];
39
- });
40
- })();
41
- };
42
- _proto.has = function has(key) {
43
- var _this = this;
44
- return _async_to_generator(function() {
45
- return _ts_generator(this, function(_state) {
46
- return [
47
- 2,
48
- _this.cache.has(key)
49
- ];
50
- });
51
- })();
52
- };
53
- _proto.delete = function _delete(key) {
54
- var _this = this;
55
- return _async_to_generator(function() {
56
- var exist;
57
- return _ts_generator(this, function(_state) {
58
- switch (_state.label) {
59
- case 0:
60
- return [
61
- 4,
62
- _this.has(key)
63
- ];
64
- case 1:
65
- exist = _state.sent();
66
- if (exist) {
67
- _this.cache.delete(key);
68
- }
69
- return [
70
- 2,
71
- exist
72
- ];
73
- }
74
- });
75
- })();
76
- };
77
- _proto.forEach = function forEach(callbackFn) {
78
- var _this = this;
79
- this.cache.forEach(function(value, key) {
80
- callbackFn(value, key, _this);
81
- });
82
- };
83
- return MemoryContainer2;
84
- }();
85
- MemoryContainer.BYTE = 1;
86
- MemoryContainer.KB = 1024 * MemoryContainer.BYTE;
87
- MemoryContainer.MB = 1024 * MemoryContainer.KB;
88
- MemoryContainer.ms = 1;
89
- MemoryContainer.second = MemoryContainer.ms * 1e3;
90
- MemoryContainer.minute = MemoryContainer.second * 60;
91
- MemoryContainer.hour = MemoryContainer.minute * 60;
92
- export {
93
- MemoryContainer
94
- };
@@ -1,11 +0,0 @@
1
- import { MemoryContainer } from "./container";
2
- import { Storage } from "./storage";
3
- import { Storage as Storage2 } from "./storage";
4
- var memoryContainer = new MemoryContainer();
5
- function createMemoryStorage(namespace) {
6
- return new Storage(namespace, memoryContainer);
7
- }
8
- export {
9
- Storage2 as Storage,
10
- createMemoryStorage
11
- };
@@ -1,135 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- var Storage = /* @__PURE__ */ function() {
5
- "use strict";
6
- function Storage2(namespace, container) {
7
- _class_call_check(this, Storage2);
8
- this.namespace = namespace;
9
- this.container = container;
10
- }
11
- var _proto = Storage2.prototype;
12
- _proto.keys = function keys() {
13
- var _this = this;
14
- return _async_to_generator(function() {
15
- var _this_forEach, _this1, _keys;
16
- return _ts_generator(this, function(_state) {
17
- _keys = [];
18
- (_this_forEach = (_this1 = _this).forEach) === null || _this_forEach === void 0 ? void 0 : _this_forEach.call(_this1, function(_, k) {
19
- _keys.push(k);
20
- });
21
- return [
22
- 2,
23
- _keys
24
- ];
25
- });
26
- })();
27
- };
28
- _proto.values = function values() {
29
- var _this = this;
30
- return _async_to_generator(function() {
31
- var _this_forEach, _this1, _values;
32
- return _ts_generator(this, function(_state) {
33
- _values = [];
34
- (_this_forEach = (_this1 = _this).forEach) === null || _this_forEach === void 0 ? void 0 : _this_forEach.call(_this1, function(v) {
35
- _values.push(v);
36
- });
37
- return [
38
- 2,
39
- _values
40
- ];
41
- });
42
- })();
43
- };
44
- _proto.get = function get(key) {
45
- var uniqueKey = this.computedUniqueKey(key);
46
- return this.container.get(uniqueKey);
47
- };
48
- _proto.set = function set(key, value) {
49
- var _this = this;
50
- return _async_to_generator(function() {
51
- var uniqueKey;
52
- return _ts_generator(this, function(_state) {
53
- switch (_state.label) {
54
- case 0:
55
- uniqueKey = _this.computedUniqueKey(key);
56
- return [
57
- 4,
58
- _this.container.set(uniqueKey, value)
59
- ];
60
- case 1:
61
- _state.sent();
62
- return [
63
- 2,
64
- _this
65
- ];
66
- }
67
- });
68
- })();
69
- };
70
- _proto.has = function has(key) {
71
- var uniqueKey = this.computedUniqueKey(key);
72
- return this.container.has(uniqueKey);
73
- };
74
- _proto.delete = function _delete(key) {
75
- var uniqueKey = this.computedUniqueKey(key);
76
- return this.container.delete(uniqueKey);
77
- };
78
- _proto.clear = function clear() {
79
- var _this = this;
80
- return _async_to_generator(function() {
81
- var _this_keys, _this1, keys;
82
- return _ts_generator(this, function(_state) {
83
- switch (_state.label) {
84
- case 0:
85
- return [
86
- 4,
87
- (_this_keys = (_this1 = _this).keys) === null || _this_keys === void 0 ? void 0 : _this_keys.call(_this1)
88
- ];
89
- case 1:
90
- keys = _state.sent();
91
- return [
92
- 4,
93
- Promise.all((keys === null || keys === void 0 ? void 0 : keys.map(function() {
94
- var _ref = _async_to_generator(function(key) {
95
- return _ts_generator(this, function(_state2) {
96
- return [
97
- 2,
98
- _this.container.delete(key)
99
- ];
100
- });
101
- });
102
- return function(key) {
103
- return _ref.apply(this, arguments);
104
- };
105
- }())) || [])
106
- ];
107
- case 2:
108
- _state.sent();
109
- return [
110
- 2
111
- ];
112
- }
113
- });
114
- })();
115
- };
116
- _proto.forEach = function forEach(fallbackFn) {
117
- var _this = this;
118
- var _this_container_forEach, _this_container;
119
- (_this_container_forEach = (_this_container = this.container).forEach) === null || _this_container_forEach === void 0 ? void 0 : _this_container_forEach.call(_this_container, function(v, k) {
120
- if (_this.checkIsOwnkey(k)) {
121
- fallbackFn(v, k, _this);
122
- }
123
- });
124
- };
125
- _proto.computedUniqueKey = function computedUniqueKey(k) {
126
- return "".concat(this.namespace, ":").concat(k);
127
- };
128
- _proto.checkIsOwnkey = function checkIsOwnkey(k) {
129
- return k.startsWith(this.namespace);
130
- };
131
- return Storage2;
132
- }();
133
- export {
134
- Storage
135
- };
@@ -1,87 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
- import { Stream } from "stream";
4
- var createReadableStreamFromReadable = function(source) {
5
- var pump = new StreamPump(source);
6
- var stream = new ReadableStream(pump, pump);
7
- return stream;
8
- };
9
- var StreamPump = /* @__PURE__ */ function() {
10
- "use strict";
11
- function StreamPump2(stream) {
12
- _class_call_check(this, StreamPump2);
13
- this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
14
- this.accumalatedSize = 0;
15
- this.stream = stream;
16
- this.enqueue = this.enqueue.bind(this);
17
- this.error = this.error.bind(this);
18
- this.close = this.close.bind(this);
19
- }
20
- var _proto = StreamPump2.prototype;
21
- _proto.size = function size(chunk) {
22
- return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
23
- };
24
- _proto.start = function start(controller) {
25
- this.controller = controller;
26
- this.stream.on("data", this.enqueue);
27
- this.stream.once("error", this.error);
28
- this.stream.once("end", this.close);
29
- this.stream.once("close", this.close);
30
- };
31
- _proto.pull = function pull() {
32
- this.resume();
33
- };
34
- _proto.cancel = function cancel(reason) {
35
- var _this = this;
36
- if (this.stream.destroy) {
37
- this.stream.destroy(reason);
38
- }
39
- process.nextTick(function() {
40
- _this.stream.off("data", _this.enqueue);
41
- _this.stream.off("error", _this.error);
42
- _this.stream.off("end", _this.close);
43
- _this.stream.off("close", _this.close);
44
- });
45
- };
46
- _proto.enqueue = function enqueue(chunk) {
47
- if (this.controller) {
48
- try {
49
- var bytes = _instanceof(chunk, Uint8Array) ? chunk : Buffer.from(chunk);
50
- var available = (this.controller.desiredSize || 0) - bytes.byteLength;
51
- this.controller.enqueue(bytes);
52
- if (available <= 0) {
53
- this.pause();
54
- }
55
- } catch (error) {
56
- this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
57
- this.cancel();
58
- }
59
- }
60
- };
61
- _proto.pause = function pause() {
62
- if (this.stream.pause) {
63
- this.stream.pause();
64
- }
65
- };
66
- _proto.resume = function resume() {
67
- if (this.stream.readable && this.stream.resume) {
68
- this.stream.resume();
69
- }
70
- };
71
- _proto.close = function close() {
72
- if (this.controller) {
73
- this.controller.close();
74
- delete this.controller;
75
- }
76
- };
77
- _proto.error = function error(error) {
78
- if (this.controller) {
79
- this.controller.error(error);
80
- delete this.controller;
81
- }
82
- };
83
- return StreamPump2;
84
- }();
85
- export {
86
- createReadableStreamFromReadable
87
- };
@@ -1,20 +0,0 @@
1
- var parsedJSONFromElement = function(id) {
2
- var elements = document.querySelectorAll("#".concat(id));
3
- if (elements.length === 0) {
4
- return void 0;
5
- }
6
- var element = elements[elements.length - 1];
7
- if (element) {
8
- try {
9
- var parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
10
- return parsed;
11
- } catch (e) {
12
- console.error("parse ".concat(id, " error"), e);
13
- return void 0;
14
- }
15
- }
16
- return void 0;
17
- };
18
- export {
19
- parsedJSONFromElement
20
- };
@@ -1,7 +0,0 @@
1
- export * from "@remix-run/router";
2
- import * as remixRouter from "@remix-run/router";
3
- var symbolName = "UNSAFE_DEFERRED_SYMBOL";
4
- var DEFERRED_SYMBOL = symbolName in remixRouter ? remixRouter[symbolName] : Symbol("deferred");
5
- export {
6
- DEFERRED_SYMBOL
7
- };
@@ -1 +0,0 @@
1
- export * from "react-router-dom";
@@ -1 +0,0 @@
1
- export * from "./nestedRoutes";
@@ -1,23 +0,0 @@
1
- function sortByUrlPath(entries) {
2
- entries.sort(function(a, b) {
3
- var length1 = a.urlPath.length;
4
- var length2 = b.urlPath.length;
5
- if (length1 < length2) {
6
- return 1;
7
- }
8
- if (length1 > length2) {
9
- return -1;
10
- }
11
- return 0;
12
- });
13
- return entries;
14
- }
15
- var matchEntry = function(pathname, entries) {
16
- sortByUrlPath(entries);
17
- return entries.find(function(entry) {
18
- return pathname.startsWith(entry.urlPath);
19
- });
20
- };
21
- export {
22
- matchEntry
23
- };
package/dist/esm/time.js DELETED
@@ -1,32 +0,0 @@
1
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
- function processHrtime(previousTimestamp) {
3
- var now = (/* @__PURE__ */ new Date()).getTime();
4
- var clocktime = now * 1e-3;
5
- var seconds = Math.floor(clocktime);
6
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
7
- if (previousTimestamp) {
8
- seconds -= previousTimestamp[0];
9
- nanoseconds -= previousTimestamp[1];
10
- if (nanoseconds < 0) {
11
- seconds--;
12
- nanoseconds += 1e9;
13
- }
14
- }
15
- return [
16
- seconds,
17
- nanoseconds
18
- ];
19
- }
20
- var getLatency = function(hrtime) {
21
- var _processHrtime = _sliced_to_array(processHrtime(hrtime), 2), s = _processHrtime[0], ns = _processHrtime[1];
22
- return s * 1e3 + ns / 1e6;
23
- };
24
- var time = function() {
25
- var hrtime = processHrtime();
26
- return function() {
27
- return getLatency(hrtime);
28
- };
29
- };
30
- export {
31
- time
32
- };
@@ -1,18 +0,0 @@
1
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
2
- var getAsyncLocalStorage = function() {
3
- if (isBrowser) {
4
- console.error("You should not get async storage in browser");
5
- return null;
6
- } else {
7
- try {
8
- var serverStorage = require("./async_storage.server");
9
- return serverStorage.getAsyncLocalStorage();
10
- } catch (err) {
11
- console.error("Failed to load server async storage", err);
12
- return null;
13
- }
14
- }
15
- };
16
- export {
17
- getAsyncLocalStorage
18
- };
@@ -1,43 +0,0 @@
1
- import * as ah from "async_hooks";
2
- var createStorage = function() {
3
- var storage2;
4
- if (typeof ah.AsyncLocalStorage !== "undefined") {
5
- storage2 = new ah.AsyncLocalStorage();
6
- }
7
- var run = function(context, cb) {
8
- if (!storage2) {
9
- throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
10
- }
11
- return new Promise(function(resolve, reject) {
12
- storage2.run(context, function() {
13
- try {
14
- return resolve(cb());
15
- } catch (error) {
16
- return reject(error);
17
- }
18
- });
19
- });
20
- };
21
- var useContext = function() {
22
- if (!storage2) {
23
- throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
24
- }
25
- var context = storage2 === null || storage2 === void 0 ? void 0 : storage2.getStore();
26
- if (!context) {
27
- throw new Error("Can't call useContext out of scope, make sure @modern-js/runtime-utils is a single version in node_modules");
28
- }
29
- return context;
30
- };
31
- return {
32
- run,
33
- useContext
34
- };
35
- };
36
- var storage = createStorage();
37
- var getAsyncLocalStorage = function() {
38
- return storage;
39
- };
40
- export {
41
- getAsyncLocalStorage,
42
- storage
43
- };