@modern-js/runtime-utils 0.0.0-nightly-20230914160548
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.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/cjs/browser/index.js +7 -0
- package/dist/cjs/browser/nestedRoutes.js +149 -0
- package/dist/cjs/browser/parsed.js +28 -0
- package/dist/cjs/node/index.js +28 -0
- package/dist/cjs/node/loaderContext/createLoaderCtx.js +34 -0
- package/dist/cjs/node/loaderContext/createRequestCtx.js +38 -0
- package/dist/cjs/node/loaderContext/index.js +22 -0
- package/dist/cjs/node/nestedRoutes.js +28 -0
- package/dist/cjs/node/router.js +6 -0
- package/dist/cjs/node/serialize.js +17 -0
- package/dist/cjs/node/storage.js +48 -0
- package/dist/cjs/remixRouter.js +6 -0
- package/dist/cjs/router.js +6 -0
- package/dist/cjs/time.js +38 -0
- package/dist/esm/browser/index.js +2 -0
- package/dist/esm/browser/nestedRoutes.js +163 -0
- package/dist/esm/browser/parsed.js +18 -0
- package/dist/esm/node/index.js +6 -0
- package/dist/esm/node/loaderContext/createLoaderCtx.js +20 -0
- package/dist/esm/node/loaderContext/createRequestCtx.js +24 -0
- package/dist/esm/node/loaderContext/index.js +3 -0
- package/dist/esm/node/nestedRoutes.js +20 -0
- package/dist/esm/node/router.js +1 -0
- package/dist/esm/node/serialize.js +6 -0
- package/dist/esm/node/storage.js +36 -0
- package/dist/esm/remixRouter.js +1 -0
- package/dist/esm/router.js +1 -0
- package/dist/esm/time.js +29 -0
- package/dist/esm-node/browser/index.js +2 -0
- package/dist/esm-node/browser/nestedRoutes.js +129 -0
- package/dist/esm-node/browser/parsed.js +18 -0
- package/dist/esm-node/node/index.js +6 -0
- package/dist/esm-node/node/loaderContext/createLoaderCtx.js +15 -0
- package/dist/esm-node/node/loaderContext/createRequestCtx.js +19 -0
- package/dist/esm-node/node/loaderContext/index.js +3 -0
- package/dist/esm-node/node/nestedRoutes.js +18 -0
- package/dist/esm-node/node/router.js +1 -0
- package/dist/esm-node/node/serialize.js +6 -0
- package/dist/esm-node/node/storage.js +38 -0
- package/dist/esm-node/remixRouter.js +1 -0
- package/dist/esm-node/router.js +1 -0
- package/dist/esm-node/time.js +28 -0
- package/dist/types/browser/index.d.ts +2 -0
- package/dist/types/browser/nestedRoutes.d.ts +13 -0
- package/dist/types/browser/parsed.d.ts +1 -0
- package/dist/types/node/index.d.ts +10 -0
- package/dist/types/node/loaderContext/createLoaderCtx.d.ts +7 -0
- package/dist/types/node/loaderContext/createRequestCtx.d.ts +7 -0
- package/dist/types/node/loaderContext/index.d.ts +4 -0
- package/dist/types/node/nestedRoutes.d.ts +3 -0
- package/dist/types/node/router.d.ts +1 -0
- package/dist/types/node/serialize.d.ts +1 -0
- package/dist/types/node/storage.d.ts +5 -0
- package/dist/types/remixRouter.d.ts +1 -0
- package/dist/types/router.d.ts +1 -0
- package/dist/types/time.d.ts +1 -0
- package/package.json +118 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export 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 _element;
|
|
10
|
+
var parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
|
|
11
|
+
return parsed;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.error("parse ".concat(id, " error"), e);
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createStorage } from "./storage";
|
|
2
|
+
var _createStorage = createStorage(), run = _createStorage.run, useHeaders = _createStorage.useContext;
|
|
3
|
+
export { run, useHeaders };
|
|
4
|
+
export { serializeJson } from "./serialize";
|
|
5
|
+
export * from "./nestedRoutes";
|
|
6
|
+
export * from "./loaderContext";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
+
export var LoaderContext = /* @__PURE__ */ function() {
|
|
3
|
+
"use strict";
|
|
4
|
+
function LoaderContext2(defaultValue) {
|
|
5
|
+
_class_call_check(this, LoaderContext2);
|
|
6
|
+
this.defaultValue = defaultValue;
|
|
7
|
+
this.symbol = Symbol("loaderContext");
|
|
8
|
+
}
|
|
9
|
+
var _proto = LoaderContext2.prototype;
|
|
10
|
+
_proto.getDefaultValue = function getDefaultValue() {
|
|
11
|
+
if (!this.defaultValue) {
|
|
12
|
+
throw new Error("Can't get defaultValue before initialed");
|
|
13
|
+
}
|
|
14
|
+
return this.defaultValue;
|
|
15
|
+
};
|
|
16
|
+
return LoaderContext2;
|
|
17
|
+
}();
|
|
18
|
+
export function createLoaderContext(defaultValue) {
|
|
19
|
+
return new LoaderContext(defaultValue);
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
+
export var RequestContext = /* @__PURE__ */ function() {
|
|
3
|
+
"use strict";
|
|
4
|
+
function RequestContext2() {
|
|
5
|
+
_class_call_check(this, RequestContext2);
|
|
6
|
+
this.store = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
var _proto = RequestContext2.prototype;
|
|
9
|
+
_proto.get = function get(loaderCtx) {
|
|
10
|
+
var symbol = loaderCtx.symbol;
|
|
11
|
+
if (this.store.get(symbol)) {
|
|
12
|
+
return this.store.get(symbol);
|
|
13
|
+
}
|
|
14
|
+
return loaderCtx.getDefaultValue();
|
|
15
|
+
};
|
|
16
|
+
_proto.set = function set(loaderCtx, value) {
|
|
17
|
+
var symbol = loaderCtx.symbol;
|
|
18
|
+
this.store.set(symbol, value);
|
|
19
|
+
};
|
|
20
|
+
return RequestContext2;
|
|
21
|
+
}();
|
|
22
|
+
export function createRequestContext() {
|
|
23
|
+
return new RequestContext();
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export var matchEntry = function(pathname, entries) {
|
|
16
|
+
sortByUrlPath(entries);
|
|
17
|
+
return entries.find(function(entry) {
|
|
18
|
+
return pathname.startsWith(entry.urlPath);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "react-router-dom/server";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as ah from "async_hooks";
|
|
2
|
+
var createStorage = function() {
|
|
3
|
+
var storage;
|
|
4
|
+
if (typeof ah.AsyncLocalStorage !== "undefined") {
|
|
5
|
+
storage = new ah.AsyncLocalStorage();
|
|
6
|
+
}
|
|
7
|
+
var run = function(context, cb) {
|
|
8
|
+
if (!storage) {
|
|
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
|
+
storage.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 (!storage) {
|
|
23
|
+
throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
|
|
24
|
+
}
|
|
25
|
+
var context = storage.getStore();
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error("Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules");
|
|
28
|
+
}
|
|
29
|
+
return context;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
run: run,
|
|
33
|
+
useContext: useContext
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export { createStorage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@remix-run/router";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "react-router-dom";
|
package/dist/esm/time.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export var time = function() {
|
|
25
|
+
var hrtime = processHrtime();
|
|
26
|
+
return function() {
|
|
27
|
+
return getLatency(hrtime);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { createRoutesFromElements, Outlet, Route } from "react-router-dom";
|
|
4
|
+
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
5
|
+
import { time } from "../time";
|
|
6
|
+
export const transformNestedRoutes = (routes, reporter) => {
|
|
7
|
+
const routeElements = [];
|
|
8
|
+
for (const route of routes) {
|
|
9
|
+
const routeElement = renderNestedRoute(route, {
|
|
10
|
+
reporter
|
|
11
|
+
});
|
|
12
|
+
routeElements.push(routeElement);
|
|
13
|
+
}
|
|
14
|
+
return createRoutesFromElements(routeElements);
|
|
15
|
+
};
|
|
16
|
+
export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
17
|
+
var _config, _children;
|
|
18
|
+
const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
|
|
19
|
+
const Component = component;
|
|
20
|
+
const { parent, DeferredDataComponent, props = {}, reporter } = options;
|
|
21
|
+
const routeProps = {
|
|
22
|
+
caseSensitive: nestedRoute.caseSensitive,
|
|
23
|
+
path: nestedRoute.path,
|
|
24
|
+
id: nestedRoute.id,
|
|
25
|
+
loader: createLoader(nestedRoute, reporter),
|
|
26
|
+
action: nestedRoute.action,
|
|
27
|
+
hasErrorBoundary: nestedRoute.hasErrorBoundary,
|
|
28
|
+
shouldRevalidate: nestedRoute.shouldRevalidate,
|
|
29
|
+
handle: {
|
|
30
|
+
...handle,
|
|
31
|
+
...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _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) {
|
|
43
|
+
var _parent;
|
|
44
|
+
if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
|
|
45
|
+
const Loading = parent.loading;
|
|
46
|
+
if (isLoadableComponent(Component)) {
|
|
47
|
+
element = /* @__PURE__ */ _jsx(Component, {
|
|
48
|
+
fallback: /* @__PURE__ */ _jsx(Loading, {})
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
element = /* @__PURE__ */ _jsx(Suspense, {
|
|
52
|
+
fallback: /* @__PURE__ */ _jsx(Loading, {}),
|
|
53
|
+
children: /* @__PURE__ */ _jsx(Component, {})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} else if (isLoadableComponent(Component) && lazyImport) {
|
|
57
|
+
element = /* @__PURE__ */ _jsx(Component, {});
|
|
58
|
+
} else if (isRoot) {
|
|
59
|
+
var _props;
|
|
60
|
+
element = /* @__PURE__ */ _jsxs(_Fragment, {
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ _jsx(Component, {
|
|
63
|
+
...props
|
|
64
|
+
}),
|
|
65
|
+
typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
|
|
66
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
} else if (lazyImport) {
|
|
71
|
+
element = /* @__PURE__ */ _jsx(Suspense, {
|
|
72
|
+
fallback: null,
|
|
73
|
+
children: /* @__PURE__ */ _jsx(Component, {})
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
element = /* @__PURE__ */ _jsx(Component, {});
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
var _parent1;
|
|
80
|
+
nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
|
|
81
|
+
routeProps.element = /* @__PURE__ */ _jsx(Outlet, {});
|
|
82
|
+
}
|
|
83
|
+
if (element) {
|
|
84
|
+
routeProps.element = element;
|
|
85
|
+
}
|
|
86
|
+
const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
|
|
87
|
+
return renderNestedRoute(childRoute, {
|
|
88
|
+
parent: nestedRoute,
|
|
89
|
+
reporter
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
const routeElement = index ? /* @__PURE__ */ _jsx(Route, {
|
|
93
|
+
...routeProps,
|
|
94
|
+
index: true
|
|
95
|
+
}, id) : /* @__PURE__ */ _jsx(Route, {
|
|
96
|
+
...routeProps,
|
|
97
|
+
index: false,
|
|
98
|
+
children: childElements
|
|
99
|
+
}, id);
|
|
100
|
+
return routeElement;
|
|
101
|
+
};
|
|
102
|
+
function createLoader(route, reporter) {
|
|
103
|
+
const { loader } = route;
|
|
104
|
+
if (loader) {
|
|
105
|
+
return async (args) => {
|
|
106
|
+
if (typeof route.lazyImport === "function") {
|
|
107
|
+
route.lazyImport();
|
|
108
|
+
}
|
|
109
|
+
const end = time();
|
|
110
|
+
const res = await loader(args);
|
|
111
|
+
const cost = end();
|
|
112
|
+
if (typeof document === "undefined" && reporter) {
|
|
113
|
+
var _reporter;
|
|
114
|
+
(_reporter = reporter) === null || _reporter === void 0 ? void 0 : _reporter.reportTiming(`${LOADER_REPORTER_NAME}-${route.id}`, cost);
|
|
115
|
+
}
|
|
116
|
+
return res;
|
|
117
|
+
};
|
|
118
|
+
} else {
|
|
119
|
+
return () => {
|
|
120
|
+
if (typeof route.lazyImport === "function") {
|
|
121
|
+
route.lazyImport();
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function isLoadableComponent(component) {
|
|
128
|
+
return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const parsedJSONFromElement = (id) => {
|
|
2
|
+
const elements = document.querySelectorAll(`#${id}`);
|
|
3
|
+
if (elements.length === 0) {
|
|
4
|
+
return void 0;
|
|
5
|
+
}
|
|
6
|
+
const element = elements[elements.length - 1];
|
|
7
|
+
if (element) {
|
|
8
|
+
try {
|
|
9
|
+
var _element;
|
|
10
|
+
const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
|
|
11
|
+
return parsed;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.error(`parse ${id} error`, e);
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return void 0;
|
|
18
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class LoaderContext {
|
|
2
|
+
getDefaultValue() {
|
|
3
|
+
if (!this.defaultValue) {
|
|
4
|
+
throw new Error("Can't get defaultValue before initialed");
|
|
5
|
+
}
|
|
6
|
+
return this.defaultValue;
|
|
7
|
+
}
|
|
8
|
+
constructor(defaultValue) {
|
|
9
|
+
this.defaultValue = defaultValue;
|
|
10
|
+
this.symbol = Symbol("loaderContext");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function createLoaderContext(defaultValue) {
|
|
14
|
+
return new LoaderContext(defaultValue);
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class RequestContext {
|
|
2
|
+
get(loaderCtx) {
|
|
3
|
+
const { symbol } = loaderCtx;
|
|
4
|
+
if (this.store.get(symbol)) {
|
|
5
|
+
return this.store.get(symbol);
|
|
6
|
+
}
|
|
7
|
+
return loaderCtx.getDefaultValue();
|
|
8
|
+
}
|
|
9
|
+
set(loaderCtx, value) {
|
|
10
|
+
const { symbol } = loaderCtx;
|
|
11
|
+
this.store.set(symbol, value);
|
|
12
|
+
}
|
|
13
|
+
constructor() {
|
|
14
|
+
this.store = /* @__PURE__ */ new Map();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function createRequestContext() {
|
|
18
|
+
return new RequestContext();
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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) {
|
|
6
|
+
return 1;
|
|
7
|
+
}
|
|
8
|
+
if (length1 > length2) {
|
|
9
|
+
return -1;
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
});
|
|
13
|
+
return entries;
|
|
14
|
+
}
|
|
15
|
+
export const matchEntry = (pathname, entries) => {
|
|
16
|
+
sortByUrlPath(entries);
|
|
17
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "react-router-dom/server";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as ah from "async_hooks";
|
|
2
|
+
const createStorage = () => {
|
|
3
|
+
let storage;
|
|
4
|
+
if (typeof ah.AsyncLocalStorage !== "undefined") {
|
|
5
|
+
storage = new ah.AsyncLocalStorage();
|
|
6
|
+
}
|
|
7
|
+
const run = (context, cb) => {
|
|
8
|
+
if (!storage) {
|
|
9
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
storage.run(context, () => {
|
|
14
|
+
try {
|
|
15
|
+
return resolve(cb());
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return reject(error);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const useContext = () => {
|
|
23
|
+
if (!storage) {
|
|
24
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
|
25
|
+
`);
|
|
26
|
+
}
|
|
27
|
+
const context = storage.getStore();
|
|
28
|
+
if (!context) {
|
|
29
|
+
throw new Error(`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`);
|
|
30
|
+
}
|
|
31
|
+
return context;
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
run,
|
|
35
|
+
useContext
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export { createStorage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@remix-run/router";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "react-router-dom";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function processHrtime(previousTimestamp) {
|
|
2
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
3
|
+
const clocktime = now * 1e-3;
|
|
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 s * 1e3 + ns / 1e6;
|
|
22
|
+
};
|
|
23
|
+
export const time = () => {
|
|
24
|
+
const hrtime = processHrtime();
|
|
25
|
+
return () => {
|
|
26
|
+
return getLatency(hrtime);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { NestedRoute, Reporter } from '@modern-js/types';
|
|
3
|
+
export declare const transformNestedRoutes: (routes: NestedRoute[], reporter: Reporter) => import("react-router-dom").RouteObject[];
|
|
4
|
+
type DeferredDataComponentType = (props?: {
|
|
5
|
+
nonce?: string;
|
|
6
|
+
}) => JSX.Element | null;
|
|
7
|
+
export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
|
|
8
|
+
parent?: NestedRoute;
|
|
9
|
+
DeferredDataComponent?: DeferredDataComponentType;
|
|
10
|
+
props?: Record<string, any>;
|
|
11
|
+
reporter?: Reporter;
|
|
12
|
+
}) => JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parsedJSONFromElement: (id: string) => any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* ssr helpers
|
|
4
|
+
*/
|
|
5
|
+
import type { IncomingHttpHeaders } from 'http';
|
|
6
|
+
declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
|
|
7
|
+
export { run, useHeaders };
|
|
8
|
+
export { serializeJson } from './serialize';
|
|
9
|
+
export * from './nestedRoutes';
|
|
10
|
+
export * from './loaderContext';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoaderContext } from './createLoaderCtx';
|
|
2
|
+
export declare class RequestContext {
|
|
3
|
+
private store;
|
|
4
|
+
get<T>(loaderCtx: LoaderContext<T>): T;
|
|
5
|
+
set<T = unknown>(loaderCtx: LoaderContext, value: T): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function createRequestContext(): RequestContext;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Reporter } from '@modern-js/types';
|
|
2
|
+
export { createRequestContext, type RequestContext } from './createRequestCtx';
|
|
3
|
+
export type { LoaderContext } from './createLoaderCtx';
|
|
4
|
+
export declare const reporterCtx: import("./createLoaderCtx").LoaderContext<Reporter>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ModernServerContext, ServerRoute } from '@modern-js/types';
|
|
2
|
+
export type ServerContext = Pick<ModernServerContext, 'logger' | 'req' | 'reporter' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
|
|
3
|
+
export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const serializeJson: (data: any) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@remix-run/router';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const time: () => () => number;
|