@bleedingdev/modern-js-runtime-utils 3.2.0-ultramodern.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/cjs/browser/deferreds.js +161 -0
  4. package/dist/cjs/browser/index.js +65 -0
  5. package/dist/cjs/browser/nestedRoutes.js +141 -0
  6. package/dist/cjs/merge.js +60 -0
  7. package/dist/cjs/node/fileReader.js +94 -0
  8. package/dist/cjs/node/index.js +99 -0
  9. package/dist/cjs/node/loaderContext/createLoaderCtx.js +51 -0
  10. package/dist/cjs/node/loaderContext/createRequestCtx.js +50 -0
  11. package/dist/cjs/node/loaderContext/index.js +41 -0
  12. package/dist/cjs/node/nestedRoutes.js +58 -0
  13. package/dist/cjs/node/sanitize.js +103 -0
  14. package/dist/cjs/node/serialize.js +49 -0
  15. package/dist/cjs/node/storer/container.js +72 -0
  16. package/dist/cjs/node/storer/index.js +44 -0
  17. package/dist/cjs/node/storer/storage.js +87 -0
  18. package/dist/cjs/parsed.js +46 -0
  19. package/dist/cjs/router.js +91 -0
  20. package/dist/cjs/rsc.js +58 -0
  21. package/dist/cjs/server/index.js +58 -0
  22. package/dist/cjs/server/nestedRoutes.js +49 -0
  23. package/dist/cjs/time.js +61 -0
  24. package/dist/cjs/universal/async_storage.js +58 -0
  25. package/dist/cjs/universal/async_storage.server.js +69 -0
  26. package/dist/cjs/universal/cache.js +381 -0
  27. package/dist/cjs/universal/request.js +86 -0
  28. package/dist/cjs/url.js +39 -0
  29. package/dist/esm/browser/deferreds.mjs +118 -0
  30. package/dist/esm/browser/index.mjs +2 -0
  31. package/dist/esm/browser/nestedRoutes.mjs +104 -0
  32. package/dist/esm/merge.mjs +26 -0
  33. package/dist/esm/node/fileReader.mjs +47 -0
  34. package/dist/esm/node/index.mjs +5 -0
  35. package/dist/esm/node/loaderContext/createLoaderCtx.mjs +14 -0
  36. package/dist/esm/node/loaderContext/createRequestCtx.mjs +16 -0
  37. package/dist/esm/node/loaderContext/index.mjs +4 -0
  38. package/dist/esm/node/nestedRoutes.mjs +1 -0
  39. package/dist/esm/node/sanitize.mjs +66 -0
  40. package/dist/esm/node/serialize.mjs +5 -0
  41. package/dist/esm/node/storer/container.mjs +38 -0
  42. package/dist/esm/node/storer/index.mjs +7 -0
  43. package/dist/esm/node/storer/storage.mjs +53 -0
  44. package/dist/esm/parsed.mjs +12 -0
  45. package/dist/esm/router.mjs +18 -0
  46. package/dist/esm/rsc.mjs +1 -0
  47. package/dist/esm/server/index.mjs +1 -0
  48. package/dist/esm/server/nestedRoutes.mjs +15 -0
  49. package/dist/esm/time.mjs +27 -0
  50. package/dist/esm/universal/async_storage.mjs +7 -0
  51. package/dist/esm/universal/async_storage.server.mjs +32 -0
  52. package/dist/esm/universal/cache.mjs +326 -0
  53. package/dist/esm/universal/request.mjs +40 -0
  54. package/dist/esm/url.mjs +5 -0
  55. package/dist/esm-node/browser/deferreds.mjs +119 -0
  56. package/dist/esm-node/browser/index.mjs +3 -0
  57. package/dist/esm-node/browser/nestedRoutes.mjs +105 -0
  58. package/dist/esm-node/merge.mjs +27 -0
  59. package/dist/esm-node/node/fileReader.mjs +48 -0
  60. package/dist/esm-node/node/index.mjs +6 -0
  61. package/dist/esm-node/node/loaderContext/createLoaderCtx.mjs +15 -0
  62. package/dist/esm-node/node/loaderContext/createRequestCtx.mjs +17 -0
  63. package/dist/esm-node/node/loaderContext/index.mjs +5 -0
  64. package/dist/esm-node/node/nestedRoutes.mjs +2 -0
  65. package/dist/esm-node/node/sanitize.mjs +67 -0
  66. package/dist/esm-node/node/serialize.mjs +6 -0
  67. package/dist/esm-node/node/storer/container.mjs +39 -0
  68. package/dist/esm-node/node/storer/index.mjs +8 -0
  69. package/dist/esm-node/node/storer/storage.mjs +54 -0
  70. package/dist/esm-node/parsed.mjs +13 -0
  71. package/dist/esm-node/router.mjs +19 -0
  72. package/dist/esm-node/rsc.mjs +2 -0
  73. package/dist/esm-node/server/index.mjs +2 -0
  74. package/dist/esm-node/server/nestedRoutes.mjs +16 -0
  75. package/dist/esm-node/time.mjs +28 -0
  76. package/dist/esm-node/universal/async_storage.mjs +25 -0
  77. package/dist/esm-node/universal/async_storage.server.mjs +33 -0
  78. package/dist/esm-node/universal/cache.mjs +327 -0
  79. package/dist/esm-node/universal/request.mjs +41 -0
  80. package/dist/esm-node/url.mjs +6 -0
  81. package/dist/types/browser/deferreds.d.ts +31 -0
  82. package/dist/types/browser/index.d.ts +2 -0
  83. package/dist/types/browser/nestedRoutes.d.ts +12 -0
  84. package/dist/types/merge.d.ts +6 -0
  85. package/dist/types/node/fileReader.d.ts +19 -0
  86. package/dist/types/node/index.d.ts +8 -0
  87. package/dist/types/node/loaderContext/createLoaderCtx.d.ts +7 -0
  88. package/dist/types/node/loaderContext/createRequestCtx.d.ts +16 -0
  89. package/dist/types/node/loaderContext/index.d.ts +4 -0
  90. package/dist/types/node/nestedRoutes.d.ts +1 -0
  91. package/dist/types/node/sanitize.d.ts +11 -0
  92. package/dist/types/node/serialize.d.ts +1 -0
  93. package/dist/types/node/storer/container.d.ts +27 -0
  94. package/dist/types/node/storer/index.d.ts +3 -0
  95. package/dist/types/node/storer/storage.d.ts +26 -0
  96. package/dist/types/parsed.d.ts +1 -0
  97. package/dist/types/router.d.ts +6 -0
  98. package/dist/types/rsc.d.ts +1 -0
  99. package/dist/types/server/index.d.ts +1 -0
  100. package/dist/types/server/nestedRoutes.d.ts +2 -0
  101. package/dist/types/time.d.ts +1 -0
  102. package/dist/types/universal/async_storage.d.ts +2 -0
  103. package/dist/types/universal/async_storage.server.d.ts +29 -0
  104. package/dist/types/universal/cache.d.ts +68 -0
  105. package/dist/types/universal/request.d.ts +17 -0
  106. package/dist/types/url.d.ts +11 -0
  107. package/package.json +197 -0
  108. package/rslib.config.mts +28 -0
  109. package/rstest.config.mts +26 -0
@@ -0,0 +1,104 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
3
+ import { Suspense } from "react";
4
+ import { Outlet, Route, createRoutesFromElements } from "react-router";
5
+ import { time } from "../time.mjs";
6
+ import { getAsyncLocalStorage } from "../universal/async_storage.mjs";
7
+ import { DeferredData, activeDeferreds as external_deferreds_mjs_activeDeferreds } from "./deferreds.mjs";
8
+ const privateDefer = (data)=>new DeferredData(data);
9
+ const transformNestedRoutes = (routes)=>{
10
+ const routeElements = [];
11
+ for (const route of routes){
12
+ const routeElement = renderNestedRoute(route);
13
+ routeElements.push(routeElement);
14
+ }
15
+ return createRoutesFromElements(routeElements);
16
+ };
17
+ const renderNestedRoute = (nestedRoute, options = {})=>{
18
+ const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
19
+ const Component = component;
20
+ const { parent, props = {} } = options;
21
+ const routeProps = {
22
+ caseSensitive: nestedRoute.caseSensitive,
23
+ path: nestedRoute.path,
24
+ id: nestedRoute.id,
25
+ loader: createLoader(nestedRoute),
26
+ action: nestedRoute.action,
27
+ hasErrorBoundary: nestedRoute.hasErrorBoundary,
28
+ shouldRevalidate: nestedRoute.shouldRevalidate,
29
+ handle: {
30
+ ...handle,
31
+ ...'object' == typeof config ? config?.handle : {}
32
+ },
33
+ index: nestedRoute.index,
34
+ element: nestedRoute.element,
35
+ errorElement: nestedRoute.errorElement
36
+ };
37
+ if (nestedRoute.error) {
38
+ const errorElement = /*#__PURE__*/ jsx(nestedRoute.error, {});
39
+ routeProps.errorElement = errorElement;
40
+ }
41
+ let element;
42
+ if (Component) if (parent?.loading && lazyImport) {
43
+ const Loading = parent.loading;
44
+ element = isLoadableComponent(Component) ? /*#__PURE__*/ jsx(Component, {
45
+ fallback: /*#__PURE__*/ jsx(Loading, {})
46
+ }) : /*#__PURE__*/ jsx(Suspense, {
47
+ fallback: /*#__PURE__*/ jsx(Loading, {}),
48
+ children: /*#__PURE__*/ jsx(Component, {})
49
+ });
50
+ } else element = isLoadableComponent(Component) && lazyImport ? /*#__PURE__*/ jsx(Component, {}) : isRoot ? /*#__PURE__*/ jsx(Component, {
51
+ ...props
52
+ }) : lazyImport ? /*#__PURE__*/ jsx(Suspense, {
53
+ fallback: null,
54
+ children: /*#__PURE__*/ jsx(Component, {})
55
+ }) : /*#__PURE__*/ jsx(Component, {});
56
+ else {
57
+ nestedRoute.loading = parent?.loading;
58
+ routeProps.element = /*#__PURE__*/ jsx(Outlet, {});
59
+ }
60
+ if (element) routeProps.element = element;
61
+ const childElements = children?.map((childRoute)=>renderNestedRoute(childRoute, {
62
+ parent: nestedRoute
63
+ }));
64
+ const routeElement = index ? /*#__PURE__*/ jsx(Route, {
65
+ ...routeProps,
66
+ index: true
67
+ }, id) : /*#__PURE__*/ jsx(Route, {
68
+ ...routeProps,
69
+ index: false,
70
+ children: childElements
71
+ }, id);
72
+ return routeElement;
73
+ };
74
+ function isPlainObject(value) {
75
+ return null != value && 'object' == typeof value && Object.getPrototypeOf(value) === Object.prototype;
76
+ }
77
+ function createLoader(route) {
78
+ const { loader } = route;
79
+ if (loader) return async (args)=>{
80
+ if ('function' == typeof route.lazyImport) route.lazyImport();
81
+ const end = time();
82
+ const res = await loader(args);
83
+ let activeDeferreds = null;
84
+ activeDeferreds = "u" < typeof document ? (await getAsyncLocalStorage())?.useContext()?.activeDeferreds : external_deferreds_mjs_activeDeferreds;
85
+ if (isPlainObject(res)) {
86
+ const deferredData = privateDefer(res);
87
+ activeDeferreds.set(route.id, deferredData);
88
+ }
89
+ const cost = end();
90
+ if ("u" < typeof document) {
91
+ const storage = await getAsyncLocalStorage();
92
+ storage?.useContext().monitors?.timing(`${LOADER_REPORTER_NAME}-${route.id?.replace(/\//g, '_')}`, cost);
93
+ }
94
+ return res;
95
+ };
96
+ return ()=>{
97
+ if ('function' == typeof route.lazyImport) route.lazyImport();
98
+ return null;
99
+ };
100
+ }
101
+ function isLoadableComponent(component) {
102
+ return component && 'Loadable' === component.displayName && component.preload && 'function' == typeof component.preload;
103
+ }
104
+ export { renderNestedRoute, transformNestedRoutes };
@@ -0,0 +1,26 @@
1
+ function isObject(obj) {
2
+ return obj && 'object' == typeof obj && !Array.isArray(obj);
3
+ }
4
+ function isComplexInstance(obj) {
5
+ if (!isObject(obj)) return false;
6
+ const hasMethods = 'function' == typeof obj.init || 'function' == typeof obj.changeLanguage || 'function' == typeof obj.t;
7
+ const hasInternalProps = void 0 !== obj.isInitialized || void 0 !== obj.language || void 0 !== obj.store;
8
+ return hasMethods || hasInternalProps;
9
+ }
10
+ function merge(target, ...sources) {
11
+ if (!sources.length) return target;
12
+ const source = sources.shift();
13
+ if (isObject(target) && isObject(source)) for(const key in source)if (isComplexInstance(source[key])) Object.assign(target, {
14
+ [key]: source[key]
15
+ });
16
+ else if (isObject(source[key])) {
17
+ if (!target[key]) Object.assign(target, {
18
+ [key]: {}
19
+ });
20
+ merge(target[key], source[key]);
21
+ } else Object.assign(target, {
22
+ [key]: source[key]
23
+ });
24
+ return merge(target, ...sources);
25
+ }
26
+ export { merge };
@@ -0,0 +1,47 @@
1
+ import fs_extra from "@modern-js/utils/fs-extra";
2
+ import { createMemoryStorage } from "./storer/index.mjs";
3
+ class FileReader {
4
+ async readFile(path, encoding = 'utf-8') {
5
+ const { fs } = this;
6
+ const _readfile = this._readFileFactory(fs);
7
+ return _readfile(path, encoding);
8
+ }
9
+ async readFileFromSystem(path, encoding = 'utf-8') {
10
+ const _readfile = this._readFileFactory(fs_extra);
11
+ return _readfile(path, encoding);
12
+ }
13
+ _readFileFactory(fs) {
14
+ return async (path, encoding = 'utf-8')=>{
15
+ const cache = await this.storage.get(path);
16
+ if (null === cache) return null;
17
+ if (cache) return this.encodingContent(cache, encoding);
18
+ const isExistFile = await new Promise((resolve)=>{
19
+ fs.stat(path, (err, stats)=>{
20
+ if (err) return void resolve(false);
21
+ stats.isFile() ? resolve(true) : resolve(false);
22
+ });
23
+ });
24
+ if (isExistFile) {
25
+ const content = await fs.promises.readFile(path);
26
+ this.storage.set(path, content);
27
+ return this.encodingContent(content, encoding);
28
+ }
29
+ this.storage.set(path, null);
30
+ return null;
31
+ };
32
+ }
33
+ reset(fs) {
34
+ fs && (this.fs = fs);
35
+ return this.storage.clear?.();
36
+ }
37
+ encodingContent(value, encoding) {
38
+ if ('utf-8' === encoding) return value.toString();
39
+ return value;
40
+ }
41
+ constructor(storage){
42
+ this.fs = fs_extra;
43
+ this.storage = storage;
44
+ }
45
+ }
46
+ const fileReader = new FileReader(createMemoryStorage('__file__system'));
47
+ export { FileReader, fileReader };
@@ -0,0 +1,5 @@
1
+ export * from "./loaderContext/index.mjs";
2
+ export * from "./nestedRoutes.mjs";
3
+ export { storage } from "../universal/async_storage.server.mjs";
4
+ export { sanitizeSSRPayload } from "./sanitize.mjs";
5
+ export { serializeJson } from "./serialize.mjs";
@@ -0,0 +1,14 @@
1
+ class LoaderContext {
2
+ getDefaultValue() {
3
+ if (!this.defaultValue) throw new Error("Can't get defaultValue before initialed");
4
+ return this.defaultValue;
5
+ }
6
+ constructor(defaultValue){
7
+ this.defaultValue = defaultValue;
8
+ this.symbol = Symbol('loaderContext');
9
+ }
10
+ }
11
+ function createLoaderContext(defaultValue) {
12
+ return new LoaderContext(defaultValue);
13
+ }
14
+ export { LoaderContext, createLoaderContext };
@@ -0,0 +1,16 @@
1
+ function createRequestContext(context) {
2
+ const _context = context || new Map();
3
+ function get(key) {
4
+ if ('string' == typeof key) return _context.get(key);
5
+ return _context.get(key.symbol) || key.getDefaultValue();
6
+ }
7
+ function set(key, value) {
8
+ if ('string' == typeof key) _context.set(key, value);
9
+ else _context.set(key.symbol, value);
10
+ }
11
+ return {
12
+ set,
13
+ get
14
+ };
15
+ }
16
+ export { createRequestContext };
@@ -0,0 +1,4 @@
1
+ import { createLoaderContext } from "./createLoaderCtx.mjs";
2
+ const reporterCtx = createLoaderContext();
3
+ export { createRequestContext } from "./createRequestCtx.mjs";
4
+ export { reporterCtx };
@@ -0,0 +1 @@
1
+ export * from "../server/nestedRoutes.mjs";
@@ -0,0 +1,66 @@
1
+ const DEFAULT_UNSAFE_SSR_HEADERS = [
2
+ 'authorization',
3
+ 'proxy-authorization',
4
+ 'cookie',
5
+ 'set-cookie',
6
+ 'x-api-key',
7
+ 'x-auth-token',
8
+ 'x-csrf-token',
9
+ 'x-xsrf-token',
10
+ 'x-forwarded-client-cert',
11
+ 'cf-access-jwt-assertion'
12
+ ];
13
+ const isPlainObject = (value)=>{
14
+ if (null === value || 'object' != typeof value) return false;
15
+ const proto = Object.getPrototypeOf(value);
16
+ return null === proto || proto === Object.prototype;
17
+ };
18
+ const isHeaderContainerKey = (key)=>{
19
+ const normalized = key.toLowerCase();
20
+ return 'headers' === normalized || normalized.endsWith('headers');
21
+ };
22
+ const normalizeHeaderName = (header)=>header.trim().toLowerCase();
23
+ const createUnsafeHeaderSet = (unsafeHeaders = [])=>{
24
+ const headers = new Set(DEFAULT_UNSAFE_SSR_HEADERS);
25
+ for (const header of unsafeHeaders){
26
+ const normalized = normalizeHeaderName(header);
27
+ if (normalized) headers.add(normalized);
28
+ }
29
+ return headers;
30
+ };
31
+ const sanitizeSSRPayload = (payload, options = {})=>{
32
+ const removed = [];
33
+ const visited = new WeakMap();
34
+ const unsafeHeaderSet = createUnsafeHeaderSet(options.unsafeHeaders);
35
+ const walk = (value, path, insideHeaderContainer)=>{
36
+ if (Array.isArray(value)) {
37
+ const cached = visited.get(value);
38
+ if (cached) return cached;
39
+ const next = [];
40
+ visited.set(value, next);
41
+ value.forEach((item, index)=>{
42
+ next.push(walk(item, `${path}[${index}]`, insideHeaderContainer));
43
+ });
44
+ return next;
45
+ }
46
+ if (!isPlainObject(value)) return value;
47
+ const cached = visited.get(value);
48
+ if (cached) return cached;
49
+ const next = {};
50
+ visited.set(value, next);
51
+ for (const [key, currentValue] of Object.entries(value)){
52
+ const nextPath = path ? `${path}.${key}` : key;
53
+ if (insideHeaderContainer && unsafeHeaderSet.has(normalizeHeaderName(key))) {
54
+ removed.push(nextPath);
55
+ continue;
56
+ }
57
+ next[key] = walk(currentValue, nextPath, isHeaderContainerKey(key));
58
+ }
59
+ return next;
60
+ };
61
+ return {
62
+ payload: walk(payload, '', options.treatRootAsHeaders ?? false),
63
+ removed
64
+ };
65
+ };
66
+ export { DEFAULT_UNSAFE_SSR_HEADERS, sanitizeSSRPayload };
@@ -0,0 +1,5 @@
1
+ import serialize_javascript from "serialize-javascript";
2
+ const serializeJson = (data)=>serialize_javascript(data, {
3
+ isJSON: true
4
+ });
5
+ export { serializeJson };
@@ -0,0 +1,38 @@
1
+ import { LRUCache } from "lru-cache";
2
+ class MemoryContainer {
3
+ async get(key) {
4
+ return this.cache.get(key);
5
+ }
6
+ async set(key, value) {
7
+ this.cache.set(key, value);
8
+ return this;
9
+ }
10
+ async has(key) {
11
+ return this.cache.has(key);
12
+ }
13
+ async delete(key) {
14
+ const exist = await this.has(key);
15
+ if (exist) this.cache.delete(key);
16
+ return exist;
17
+ }
18
+ forEach(callbackFn) {
19
+ this.cache.forEach((value, key)=>{
20
+ callbackFn(value, key, this);
21
+ });
22
+ }
23
+ constructor({ max, maxAge } = {}){
24
+ this.cache = new LRUCache({
25
+ maxSize: (max || 256) * MemoryContainer.MB,
26
+ ttl: maxAge || MemoryContainer.hour,
27
+ sizeCalculation: (value, key)=>JSON.stringify(value).length
28
+ });
29
+ }
30
+ }
31
+ MemoryContainer.BYTE = 1;
32
+ MemoryContainer.KB = 1024 * MemoryContainer.BYTE;
33
+ MemoryContainer.MB = 1024 * MemoryContainer.KB;
34
+ MemoryContainer.ms = 1;
35
+ MemoryContainer.second = 1000 * MemoryContainer.ms;
36
+ MemoryContainer.minute = 60 * MemoryContainer.second;
37
+ MemoryContainer.hour = 60 * MemoryContainer.minute;
38
+ export { MemoryContainer };
@@ -0,0 +1,7 @@
1
+ import { MemoryContainer } from "./container.mjs";
2
+ import { Storage } from "./storage.mjs";
3
+ const memoryContainer = new MemoryContainer();
4
+ function createMemoryStorage(namespace) {
5
+ return new Storage(namespace, memoryContainer);
6
+ }
7
+ export { Storage, createMemoryStorage };
@@ -0,0 +1,53 @@
1
+ class Storage {
2
+ async keys() {
3
+ const _keys = [];
4
+ this.forEach?.((_, k)=>{
5
+ _keys.push(k);
6
+ });
7
+ return _keys;
8
+ }
9
+ async values() {
10
+ const _values = [];
11
+ this.forEach?.((v)=>{
12
+ _values.push(v);
13
+ });
14
+ return _values;
15
+ }
16
+ get(key) {
17
+ const uniqueKey = this.computedUniqueKey(key);
18
+ return this.container.get(uniqueKey);
19
+ }
20
+ async set(key, value) {
21
+ const uniqueKey = this.computedUniqueKey(key);
22
+ await this.container.set(uniqueKey, value);
23
+ return this;
24
+ }
25
+ has(key) {
26
+ const uniqueKey = this.computedUniqueKey(key);
27
+ return this.container.has(uniqueKey);
28
+ }
29
+ delete(key) {
30
+ const uniqueKey = this.computedUniqueKey(key);
31
+ return this.container.delete(uniqueKey);
32
+ }
33
+ async clear() {
34
+ const keys = await this.keys?.();
35
+ await Promise.all(keys?.map(async (key)=>this.container.delete(key)) || []);
36
+ }
37
+ forEach(fallbackFn) {
38
+ this.container.forEach?.((v, k)=>{
39
+ if (this.checkIsOwnkey(k)) fallbackFn(v, k, this);
40
+ });
41
+ }
42
+ computedUniqueKey(k) {
43
+ return `${this.namespace}:${k}`;
44
+ }
45
+ checkIsOwnkey(k) {
46
+ return k.startsWith(this.namespace);
47
+ }
48
+ constructor(namespace, container){
49
+ this.namespace = namespace;
50
+ this.container = container;
51
+ }
52
+ }
53
+ export { Storage };
@@ -0,0 +1,12 @@
1
+ const parsedJSONFromElement = (id)=>{
2
+ const elements = document.querySelectorAll(`#${id}`);
3
+ if (0 === elements.length) return;
4
+ const element = elements[elements.length - 1];
5
+ if (element) try {
6
+ const parsed = JSON.parse(element?.textContent || '');
7
+ return parsed;
8
+ } catch (e) {
9
+ console.error(`parse ${id} error`, e);
10
+ }
11
+ };
12
+ export { parsedJSONFromElement };
@@ -0,0 +1,18 @@
1
+ export * from "react-router";
2
+ const DEFERRED_SYMBOL = Symbol('deferred');
3
+ const json = (data, init)=>{
4
+ const responseInit = init ? 'number' == typeof init ? {
5
+ status: init
6
+ } : init : void 0;
7
+ return new Response(JSON.stringify(data), responseInit);
8
+ };
9
+ const defer = (data, init)=>{
10
+ if (void 0 === init) return data;
11
+ {
12
+ const responseInit = init ? 'number' == typeof init ? {
13
+ status: init
14
+ } : init : void 0;
15
+ return new Response(JSON.stringify(data), responseInit);
16
+ }
17
+ };
18
+ export { DEFERRED_SYMBOL, defer, json };
@@ -0,0 +1 @@
1
+ export * from "react-router";
@@ -0,0 +1 @@
1
+ export * from "./nestedRoutes.mjs";
@@ -0,0 +1,15 @@
1
+ function sortByUrlPath(entries) {
2
+ entries.sort(function(a, b) {
3
+ const length1 = a.urlPath.length;
4
+ const length2 = b.urlPath.length;
5
+ if (length1 < length2) return 1;
6
+ if (length1 > length2) return -1;
7
+ return 0;
8
+ });
9
+ return entries;
10
+ }
11
+ const matchEntry = (pathname, entries)=>{
12
+ sortByUrlPath(entries);
13
+ return entries.find((entry)=>pathname.startsWith(entry.urlPath));
14
+ };
15
+ export { matchEntry };
@@ -0,0 +1,27 @@
1
+ function processHrtime(previousTimestamp) {
2
+ const now = new Date().getTime();
3
+ const clocktime = 1e-3 * now;
4
+ let seconds = Math.floor(clocktime);
5
+ let nanoseconds = Math.floor(clocktime % 1 * 1e9);
6
+ if (previousTimestamp) {
7
+ seconds -= previousTimestamp[0];
8
+ nanoseconds -= previousTimestamp[1];
9
+ if (nanoseconds < 0) {
10
+ seconds--;
11
+ nanoseconds += 1e9;
12
+ }
13
+ }
14
+ return [
15
+ seconds,
16
+ nanoseconds
17
+ ];
18
+ }
19
+ const getLatency = (hrtime)=>{
20
+ const [s, ns] = processHrtime(hrtime);
21
+ return 1e3 * s + ns / 1e6;
22
+ };
23
+ const time = ()=>{
24
+ const hrtime = processHrtime();
25
+ return ()=>getLatency(hrtime);
26
+ };
27
+ export { time };
@@ -0,0 +1,7 @@
1
+ const isBrowser = "u" > typeof window && void 0 !== window.document;
2
+ const getAsyncLocalStorage = async ()=>{
3
+ if (!isBrowser) return null;
4
+ console.error('You should not get async storage in browser');
5
+ return null;
6
+ };
7
+ export { getAsyncLocalStorage };
@@ -0,0 +1,32 @@
1
+ import * as __rspack_external_async_hooks from "async_hooks";
2
+ const createStorage = ()=>{
3
+ let storage;
4
+ if (void 0 !== __rspack_external_async_hooks.AsyncLocalStorage) storage = new __rspack_external_async_hooks.AsyncLocalStorage();
5
+ const run = (context, cb)=>{
6
+ if (!storage) throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
7
+ `);
8
+ return new Promise((resolve, reject)=>{
9
+ storage.run(context, ()=>{
10
+ try {
11
+ return resolve(cb());
12
+ } catch (error) {
13
+ return reject(error);
14
+ }
15
+ });
16
+ });
17
+ };
18
+ const useContext = ()=>{
19
+ if (!storage) throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
20
+ `);
21
+ const context = storage?.getStore();
22
+ if (!context) throw new Error("Can't call useContext out of scope, make sure @modern-js/runtime-utils is a single version in node_modules");
23
+ return context;
24
+ };
25
+ return {
26
+ run,
27
+ useContext
28
+ };
29
+ };
30
+ const async_storage_server_storage = createStorage();
31
+ const getAsyncLocalStorage = async ()=>async_storage_server_storage;
32
+ export { async_storage_server_storage as storage, getAsyncLocalStorage };