@modern-js/runtime-utils 2.49.3 → 2.50.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.
- package/dist/cjs/node/loaderContext/createRequestCtx.js +17 -17
- package/dist/esm/node/loaderContext/createRequestCtx.js +17 -21
- package/dist/esm-node/node/loaderContext/createRequestCtx.js +17 -16
- package/dist/types/node/loaderContext/createRequestCtx.d.ts +14 -5
- package/dist/types/node/loaderContext/index.d.ts +12 -0
- package/package.json +5 -5
|
@@ -18,31 +18,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var createRequestCtx_exports = {};
|
|
20
20
|
__export(createRequestCtx_exports, {
|
|
21
|
-
RequestContext: () => RequestContext,
|
|
22
21
|
createRequestContext: () => createRequestContext
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(createRequestCtx_exports);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
24
|
+
function createRequestContext(context) {
|
|
25
|
+
const _context = context || /* @__PURE__ */ new Map();
|
|
26
|
+
function get(key) {
|
|
27
|
+
if (typeof key === "string") {
|
|
28
|
+
return _context.get(key);
|
|
29
|
+
} else {
|
|
30
|
+
return _context.get(key.symbol) || key.getDefaultValue();
|
|
30
31
|
}
|
|
31
|
-
return loaderCtx.getDefaultValue();
|
|
32
32
|
}
|
|
33
|
-
set(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
function set(key, value) {
|
|
34
|
+
if (typeof key === "string") {
|
|
35
|
+
_context.set(key, value);
|
|
36
|
+
} else {
|
|
37
|
+
_context.set(key.symbol, value);
|
|
38
|
+
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
return {
|
|
41
|
+
set,
|
|
42
|
+
get
|
|
43
|
+
};
|
|
43
44
|
}
|
|
44
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
46
|
0 && (module.exports = {
|
|
46
|
-
RequestContext,
|
|
47
47
|
createRequestContext
|
|
48
48
|
});
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function createRequestContext(context) {
|
|
2
|
+
var _context = context || /* @__PURE__ */ new Map();
|
|
3
|
+
function get(key) {
|
|
4
|
+
if (typeof key === "string") {
|
|
5
|
+
return _context.get(key);
|
|
6
|
+
} else {
|
|
7
|
+
return _context.get(key.symbol) || key.getDefaultValue();
|
|
8
|
+
}
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function set(key, value) {
|
|
11
|
+
if (typeof key === "string") {
|
|
12
|
+
_context.set(key, value);
|
|
13
|
+
} else {
|
|
14
|
+
_context.set(key.symbol, value);
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.store.set(symbol, value);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
set,
|
|
19
|
+
get
|
|
19
20
|
};
|
|
20
|
-
return RequestContext2;
|
|
21
|
-
}();
|
|
22
|
-
function createRequestContext() {
|
|
23
|
-
return new RequestContext();
|
|
24
21
|
}
|
|
25
22
|
export {
|
|
26
|
-
RequestContext,
|
|
27
23
|
createRequestContext
|
|
28
24
|
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
1
|
+
function createRequestContext(context) {
|
|
2
|
+
const _context = context || /* @__PURE__ */ new Map();
|
|
3
|
+
function get(key) {
|
|
4
|
+
if (typeof key === "string") {
|
|
5
|
+
return _context.get(key);
|
|
6
|
+
} else {
|
|
7
|
+
return _context.get(key.symbol) || key.getDefaultValue();
|
|
6
8
|
}
|
|
7
|
-
return loaderCtx.getDefaultValue();
|
|
8
9
|
}
|
|
9
|
-
set(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
function set(key, value) {
|
|
11
|
+
if (typeof key === "string") {
|
|
12
|
+
_context.set(key, value);
|
|
13
|
+
} else {
|
|
14
|
+
_context.set(key.symbol, value);
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return {
|
|
18
|
+
set,
|
|
19
|
+
get
|
|
20
|
+
};
|
|
19
21
|
}
|
|
20
22
|
export {
|
|
21
|
-
RequestContext,
|
|
22
23
|
createRequestContext
|
|
23
24
|
};
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { RequestPayload } from '@modern-js/types';
|
|
1
2
|
import { LoaderContext } from './createLoaderCtx';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
set<T = unknown>(loaderCtx: LoaderContext, value: T): void;
|
|
3
|
+
interface Get<P extends Record<string, unknown>> {
|
|
4
|
+
<Key extends keyof P>(key: Key): P[Key];
|
|
5
|
+
<T>(key: LoaderContext<T>): T;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface Set<P extends Record<string, unknown>> {
|
|
8
|
+
<Key extends keyof P>(key: Key, value: P[Key]): void;
|
|
9
|
+
<T>(key: LoaderContext<T>, value: T): void;
|
|
10
|
+
}
|
|
11
|
+
export type RequestContext<P extends Record<string, unknown> = {}> = {
|
|
12
|
+
get: Get<P & RequestPayload>;
|
|
13
|
+
set: Set<P & RequestPayload>;
|
|
14
|
+
};
|
|
15
|
+
export declare function createRequestContext<P extends Record<string, unknown>>(context?: Map<string | symbol, unknown>): RequestContext<P>;
|
|
16
|
+
export {};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { Reporter } from '@modern-js/types';
|
|
2
2
|
export { createRequestContext, type RequestContext } from './createRequestCtx';
|
|
3
3
|
export type { LoaderContext } from './createLoaderCtx';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
* Use `context.get('reporter')` instead of `context.get(reporterCtx)`. The `reporterCtx` will be removed in next major version.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* const loader = ({ context }: LoaderFunctionArgs) => {
|
|
11
|
+
* const reporter = context?.get('reporter')
|
|
12
|
+
* // doSomething
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
4
16
|
export declare const reporterCtx: import("./createLoaderCtx").LoaderContext<Reporter>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.50.0",
|
|
19
19
|
"_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
|
|
20
20
|
"exports": {
|
|
21
21
|
"./router": {
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"react-router-dom": "6.22.0",
|
|
115
115
|
"@remix-run/router": "1.15.0",
|
|
116
116
|
"@swc/helpers": "0.5.3",
|
|
117
|
-
"@modern-js/utils": "2.
|
|
117
|
+
"@modern-js/utils": "2.50.0"
|
|
118
118
|
},
|
|
119
119
|
"peerDependencies": {
|
|
120
120
|
"react": ">=17.0.0",
|
|
@@ -137,9 +137,9 @@
|
|
|
137
137
|
"jest": "^29",
|
|
138
138
|
"typescript": "^5",
|
|
139
139
|
"@types/serialize-javascript": "^5.0.1",
|
|
140
|
-
"@modern-js/types": "2.
|
|
141
|
-
"@scripts/build": "2.
|
|
142
|
-
"@scripts/jest-config": "2.
|
|
140
|
+
"@modern-js/types": "2.50.0",
|
|
141
|
+
"@scripts/build": "2.50.0",
|
|
142
|
+
"@scripts/jest-config": "2.50.0"
|
|
143
143
|
},
|
|
144
144
|
"sideEffects": false,
|
|
145
145
|
"scripts": {
|