@shuvi/platform-shared 1.0.8 → 1.0.9
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.
|
@@ -5,5 +5,5 @@ interface Result<T> {
|
|
|
5
5
|
result?: T;
|
|
6
6
|
}
|
|
7
7
|
export declare function runInParallerAndBail<T>(fns: Array<() => Promise<T> | T>): Promise<Result<T>[]>;
|
|
8
|
-
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { query, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
8
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { pathname, query, params, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
9
9
|
export {};
|
|
@@ -71,7 +71,7 @@ function errorHelper(msg, statusCode = 500) {
|
|
|
71
71
|
invariant(statusCode >= 400 && statusCode < 600, 'status code should be 4xx and 5xx');
|
|
72
72
|
throw response(msg, { status: statusCode });
|
|
73
73
|
}
|
|
74
|
-
export function runLoaders(matches, loadersByRouteId, { query, req, getAppContext }) {
|
|
74
|
+
export function runLoaders(matches, loadersByRouteId, { pathname, query, params, req, getAppContext }) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const loaderDatas = {};
|
|
77
77
|
if (!matches.length) {
|
|
@@ -85,7 +85,9 @@ export function runLoaders(matches, loadersByRouteId, { query, req, getAppContex
|
|
|
85
85
|
}
|
|
86
86
|
let res;
|
|
87
87
|
try {
|
|
88
|
-
const value = yield loaderFn(Object.assign({ pathname
|
|
88
|
+
const value = yield loaderFn(Object.assign({ pathname,
|
|
89
|
+
params,
|
|
90
|
+
query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
89
91
|
if (value === undefined) {
|
|
90
92
|
throw new Error(`You defined a loader for route "${match.route.path}" but didn't return ` +
|
|
91
93
|
`anything from your \`loader\` function. Please return a value or \`null\`.`);
|
|
@@ -3,8 +3,10 @@ import { IURLQuery, IURLParams } from '../routerTypes';
|
|
|
3
3
|
import { IAppContext } from '../applicationTypes';
|
|
4
4
|
import { Response } from '../response';
|
|
5
5
|
export interface LoaderContextOptions {
|
|
6
|
-
req?:
|
|
7
|
-
|
|
6
|
+
req?: IRouteLoaderContext['req'];
|
|
7
|
+
pathname: IRouteLoaderContext['pathname'];
|
|
8
|
+
query: IRouteLoaderContext['query'];
|
|
9
|
+
params: IRouteLoaderContext['params'];
|
|
8
10
|
getAppContext: () => IAppContext;
|
|
9
11
|
}
|
|
10
12
|
export declare type RedirectFunction = (to: string, status?: number) => any;
|
|
@@ -5,5 +5,5 @@ interface Result<T> {
|
|
|
5
5
|
result?: T;
|
|
6
6
|
}
|
|
7
7
|
export declare function runInParallerAndBail<T>(fns: Array<() => Promise<T> | T>): Promise<Result<T>[]>;
|
|
8
|
-
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { query, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
8
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, { pathname, query, params, req, getAppContext }: LoaderContextOptions): Promise<LoaderDataRecord>;
|
|
9
9
|
export {};
|
|
@@ -78,7 +78,7 @@ function errorHelper(msg, statusCode = 500) {
|
|
|
78
78
|
(0, invariant_1.default)(statusCode >= 400 && statusCode < 600, 'status code should be 4xx and 5xx');
|
|
79
79
|
throw (0, response_1.response)(msg, { status: statusCode });
|
|
80
80
|
}
|
|
81
|
-
function runLoaders(matches, loadersByRouteId, { query, req, getAppContext }) {
|
|
81
|
+
function runLoaders(matches, loadersByRouteId, { pathname, query, params, req, getAppContext }) {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
83
|
const loaderDatas = {};
|
|
84
84
|
if (!matches.length) {
|
|
@@ -92,7 +92,9 @@ function runLoaders(matches, loadersByRouteId, { query, req, getAppContext }) {
|
|
|
92
92
|
}
|
|
93
93
|
let res;
|
|
94
94
|
try {
|
|
95
|
-
const value = yield loaderFn(Object.assign({ pathname
|
|
95
|
+
const value = yield loaderFn(Object.assign({ pathname,
|
|
96
|
+
params,
|
|
97
|
+
query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
96
98
|
if (value === undefined) {
|
|
97
99
|
throw new Error(`You defined a loader for route "${match.route.path}" but didn't return ` +
|
|
98
100
|
`anything from your \`loader\` function. Please return a value or \`null\`.`);
|
|
@@ -3,8 +3,10 @@ import { IURLQuery, IURLParams } from '../routerTypes';
|
|
|
3
3
|
import { IAppContext } from '../applicationTypes';
|
|
4
4
|
import { Response } from '../response';
|
|
5
5
|
export interface LoaderContextOptions {
|
|
6
|
-
req?:
|
|
7
|
-
|
|
6
|
+
req?: IRouteLoaderContext['req'];
|
|
7
|
+
pathname: IRouteLoaderContext['pathname'];
|
|
8
|
+
query: IRouteLoaderContext['query'];
|
|
9
|
+
params: IRouteLoaderContext['params'];
|
|
8
10
|
getAppContext: () => IAppContext;
|
|
9
11
|
}
|
|
10
12
|
export declare type RedirectFunction = (to: string, status?: number) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -83,17 +83,17 @@
|
|
|
83
83
|
"node": ">= 12.0.0"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@shuvi/hook": "1.0.
|
|
87
|
-
"doura": "0.0.
|
|
88
|
-
"@shuvi/router": "1.0.
|
|
89
|
-
"@shuvi/runtime": "1.0.
|
|
90
|
-
"@shuvi/shared": "1.0.
|
|
91
|
-
"@shuvi/toolpack": "1.0.
|
|
92
|
-
"@shuvi/utils": "1.0.
|
|
86
|
+
"@shuvi/hook": "1.0.9",
|
|
87
|
+
"doura": "0.0.7",
|
|
88
|
+
"@shuvi/router": "1.0.9",
|
|
89
|
+
"@shuvi/runtime": "1.0.9",
|
|
90
|
+
"@shuvi/shared": "1.0.9",
|
|
91
|
+
"@shuvi/toolpack": "1.0.9",
|
|
92
|
+
"@shuvi/utils": "1.0.9",
|
|
93
93
|
"redux": "4.1.2"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@shuvi/service": "1.0.
|
|
96
|
+
"@shuvi/service": "1.0.9"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@shuvi/service": "workspace:*",
|