@shuvi/platform-shared 1.0.37 → 1.0.39
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/esm/shared/application.d.ts +2 -2
- package/esm/shared/application.js +4 -2
- package/esm/shared/applicationTypes.d.ts +2 -2
- package/esm/shared/helper/getFilesOfRoute.d.ts +1 -1
- package/esm/shared/loader/loader.d.ts +3 -2
- package/esm/shared/loader/loader.js +7 -5
- package/esm/shared/router.d.ts +1 -1
- package/esm/shared/routerTypes.d.ts +3 -1
- package/esm/shared/runtimPlugin.d.ts +6 -2
- package/lib/shared/application.d.ts +2 -2
- package/lib/shared/application.js +4 -2
- package/lib/shared/applicationTypes.d.ts +2 -2
- package/lib/shared/helper/getFilesOfRoute.d.ts +1 -1
- package/lib/shared/loader/loader.d.ts +3 -2
- package/lib/shared/loader/loader.js +9 -6
- package/lib/shared/router.d.ts +1 -1
- package/lib/shared/routerTypes.d.ts +3 -1
- package/lib/shared/runtimPlugin.d.ts +6 -2
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRouter
|
|
1
|
+
import { IRouter } from './routerTypes';
|
|
2
2
|
import { Doura, Application, IAppContext, ApplicationInternalOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class ApplicationImpl<Config extends {} = {}> {
|
|
4
4
|
private _router;
|
|
@@ -11,7 +11,7 @@ export declare class ApplicationImpl<Config extends {} = {}> {
|
|
|
11
11
|
private _loader;
|
|
12
12
|
private _getLoaders;
|
|
13
13
|
constructor(options: ApplicationInternalOptions<Config>);
|
|
14
|
-
get router(): IRouter
|
|
14
|
+
get router(): IRouter;
|
|
15
15
|
get config(): Config;
|
|
16
16
|
get context(): IAppContext;
|
|
17
17
|
get pluginManager(): import("@shuvi/hook").HookManager<import("./runtimPlugin").RuntimePluginHooks, void>;
|
|
@@ -62,8 +62,8 @@ export class ApplicationImpl {
|
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
yield this._initPlugin();
|
|
64
64
|
yield this._initAppContext();
|
|
65
|
-
yield this._initAppComponent();
|
|
66
65
|
this._router.init();
|
|
66
|
+
yield this._initAppComponent();
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
get store() {
|
|
@@ -89,7 +89,9 @@ export class ApplicationImpl {
|
|
|
89
89
|
}
|
|
90
90
|
_initAppContext() {
|
|
91
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
yield this._pluginManager.runner.appContext(this._context
|
|
92
|
+
yield this._pluginManager.runner.appContext(this._context, {
|
|
93
|
+
router: this._router
|
|
94
|
+
});
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
_initAppComponent() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Doura } from 'doura';
|
|
2
2
|
import { CustomAppContext } from '@shuvi/runtime';
|
|
3
|
-
import { IRouter
|
|
3
|
+
import { IRouter } from './routerTypes';
|
|
4
4
|
import { IPluginList } from './runtimPlugin';
|
|
5
5
|
import { Loader } from './loader';
|
|
6
6
|
export declare type Loaders = Record<string, Loader>;
|
|
@@ -27,7 +27,7 @@ export declare type IAppState = {
|
|
|
27
27
|
export interface Application<Config extends {} = {}> {
|
|
28
28
|
readonly config: Config;
|
|
29
29
|
readonly context: IAppContext;
|
|
30
|
-
readonly router: IRouter
|
|
30
|
+
readonly router: IRouter;
|
|
31
31
|
readonly appComponent: any;
|
|
32
32
|
readonly store: Doura;
|
|
33
33
|
readonly error: IErrorState['error'];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IRouteMatch, IPageRouteRecord } from '../routerTypes';
|
|
2
|
-
import { Loader, LoaderContextOptions, LoaderDataRecord } from './types';
|
|
2
|
+
import { Loader, LoaderContextOptions, LoaderDataRecord, IRouteLoaderContext } from './types';
|
|
3
3
|
interface Result<T> {
|
|
4
4
|
error?: unknown;
|
|
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
|
|
8
|
+
export declare function createLoaderContext({ pathname, query, params, req, getAppContext }: LoaderContextOptions): IRouteLoaderContext;
|
|
9
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, loaderContext: IRouteLoaderContext): Promise<LoaderDataRecord>;
|
|
9
10
|
export {};
|
|
@@ -71,13 +71,17 @@ 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
|
|
74
|
+
export function createLoaderContext({ pathname, query, params, req, getAppContext }) {
|
|
75
|
+
return Object.assign({ pathname,
|
|
76
|
+
params,
|
|
77
|
+
query, redirect: redirectHelper, error: errorHelper, appContext: getAppContext() }, (req ? { req } : {}));
|
|
78
|
+
}
|
|
79
|
+
export function runLoaders(matches, loadersByRouteId, loaderContext) {
|
|
75
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
81
|
const loaderDatas = {};
|
|
77
82
|
if (!matches.length) {
|
|
78
83
|
return loaderDatas;
|
|
79
84
|
}
|
|
80
|
-
const appContext = getAppContext();
|
|
81
85
|
const createLoader = (match) => () => __awaiter(this, void 0, void 0, function* () {
|
|
82
86
|
const loaderFn = loadersByRouteId[match.route.id];
|
|
83
87
|
if (typeof loaderFn !== 'function') {
|
|
@@ -86,9 +90,7 @@ export function runLoaders(matches, loadersByRouteId, { pathname, query, params,
|
|
|
86
90
|
let res;
|
|
87
91
|
let error;
|
|
88
92
|
try {
|
|
89
|
-
const value = yield loaderFn(
|
|
90
|
-
params,
|
|
91
|
-
query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
93
|
+
const value = yield loaderFn(loaderContext);
|
|
92
94
|
if (value === undefined) {
|
|
93
95
|
error = new Error(`You defined a loader for route "${match.route.path}" but didn't return ` +
|
|
94
96
|
`anything from your \`loader\` function. Please return a value or \`null\`.`);
|
package/esm/shared/router.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { matchPathname, rankRouteBranches, parseQuery, createRouter, createBrowserHistory, createHashHistory, createMemoryHistory } from '@shuvi/router';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ParsedQuery, IParams, IRouteRecord } from '@shuvi/router';
|
|
2
|
-
|
|
2
|
+
import { IRouter as IRouter_, IRoute, IRouteMatch, PathRecord } from '@shuvi/router';
|
|
3
|
+
export { IRoute, IRouteMatch, PathRecord };
|
|
3
4
|
export declare type IURLQuery = ParsedQuery;
|
|
4
5
|
export declare type IURLParams = IParams;
|
|
6
|
+
export declare type IRouter = IRouter_<IPageRouteRecord>;
|
|
5
7
|
export interface IPageRouteRecord extends IRouteRecord {
|
|
6
8
|
id: string;
|
|
7
9
|
path: string;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { IPluginInstance, IPluginHandlers, HookMap } from '@shuvi/hook';
|
|
2
2
|
import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
3
3
|
import { IAppContext } from './applicationTypes';
|
|
4
|
+
import { IRouter } from './routerTypes';
|
|
4
5
|
export declare type AppComponent = unknown;
|
|
6
|
+
export declare type AppContextCtx = {
|
|
7
|
+
router: IRouter;
|
|
8
|
+
};
|
|
5
9
|
declare const init: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext,
|
|
10
|
+
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext, AppContextCtx, void>;
|
|
7
11
|
declare const appComponent: import("@shuvi/hook").AsyncSeriesWaterfallHook<unknown, IAppContext>;
|
|
8
12
|
declare const dispose: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
13
|
export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
10
14
|
init: typeof init;
|
|
11
|
-
appComponent: typeof appComponent;
|
|
12
15
|
appContext: typeof appContext;
|
|
16
|
+
appComponent: typeof appComponent;
|
|
13
17
|
dispose: typeof dispose;
|
|
14
18
|
}
|
|
15
19
|
export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRuntimePluginHooks {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRouter
|
|
1
|
+
import { IRouter } from './routerTypes';
|
|
2
2
|
import { Doura, Application, IAppContext, ApplicationInternalOptions, IRerenderConfig, IError } from './applicationTypes';
|
|
3
3
|
export declare class ApplicationImpl<Config extends {} = {}> {
|
|
4
4
|
private _router;
|
|
@@ -11,7 +11,7 @@ export declare class ApplicationImpl<Config extends {} = {}> {
|
|
|
11
11
|
private _loader;
|
|
12
12
|
private _getLoaders;
|
|
13
13
|
constructor(options: ApplicationInternalOptions<Config>);
|
|
14
|
-
get router(): IRouter
|
|
14
|
+
get router(): IRouter;
|
|
15
15
|
get config(): Config;
|
|
16
16
|
get context(): IAppContext;
|
|
17
17
|
get pluginManager(): import("@shuvi/hook").HookManager<import("./runtimPlugin").RuntimePluginHooks, void>;
|
|
@@ -65,8 +65,8 @@ class ApplicationImpl {
|
|
|
65
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
66
|
yield this._initPlugin();
|
|
67
67
|
yield this._initAppContext();
|
|
68
|
-
yield this._initAppComponent();
|
|
69
68
|
this._router.init();
|
|
69
|
+
yield this._initAppComponent();
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
get store() {
|
|
@@ -92,7 +92,9 @@ class ApplicationImpl {
|
|
|
92
92
|
}
|
|
93
93
|
_initAppContext() {
|
|
94
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
yield this._pluginManager.runner.appContext(this._context
|
|
95
|
+
yield this._pluginManager.runner.appContext(this._context, {
|
|
96
|
+
router: this._router
|
|
97
|
+
});
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
100
|
_initAppComponent() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Doura } from 'doura';
|
|
2
2
|
import { CustomAppContext } from '@shuvi/runtime';
|
|
3
|
-
import { IRouter
|
|
3
|
+
import { IRouter } from './routerTypes';
|
|
4
4
|
import { IPluginList } from './runtimPlugin';
|
|
5
5
|
import { Loader } from './loader';
|
|
6
6
|
export declare type Loaders = Record<string, Loader>;
|
|
@@ -27,7 +27,7 @@ export declare type IAppState = {
|
|
|
27
27
|
export interface Application<Config extends {} = {}> {
|
|
28
28
|
readonly config: Config;
|
|
29
29
|
readonly context: IAppContext;
|
|
30
|
-
readonly router: IRouter
|
|
30
|
+
readonly router: IRouter;
|
|
31
31
|
readonly appComponent: any;
|
|
32
32
|
readonly store: Doura;
|
|
33
33
|
readonly error: IErrorState['error'];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IRouteMatch, IPageRouteRecord } from '../routerTypes';
|
|
2
|
-
import { Loader, LoaderContextOptions, LoaderDataRecord } from './types';
|
|
2
|
+
import { Loader, LoaderContextOptions, LoaderDataRecord, IRouteLoaderContext } from './types';
|
|
3
3
|
interface Result<T> {
|
|
4
4
|
error?: unknown;
|
|
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
|
|
8
|
+
export declare function createLoaderContext({ pathname, query, params, req, getAppContext }: LoaderContextOptions): IRouteLoaderContext;
|
|
9
|
+
export declare function runLoaders(matches: IRouteMatch<IPageRouteRecord>[], loadersByRouteId: Record<string, Loader>, loaderContext: IRouteLoaderContext): Promise<LoaderDataRecord>;
|
|
9
10
|
export {};
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.runLoaders = exports.runInParallerAndBail = void 0;
|
|
15
|
+
exports.runLoaders = exports.createLoaderContext = exports.runInParallerAndBail = void 0;
|
|
16
16
|
const invariant_1 = __importDefault(require("@shuvi/utils/invariant"));
|
|
17
17
|
const response_1 = require("../response");
|
|
18
18
|
// todo: add unit tests
|
|
@@ -78,13 +78,18 @@ 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
|
|
81
|
+
function createLoaderContext({ pathname, query, params, req, getAppContext }) {
|
|
82
|
+
return Object.assign({ pathname,
|
|
83
|
+
params,
|
|
84
|
+
query, redirect: redirectHelper, error: errorHelper, appContext: getAppContext() }, (req ? { req } : {}));
|
|
85
|
+
}
|
|
86
|
+
exports.createLoaderContext = createLoaderContext;
|
|
87
|
+
function runLoaders(matches, loadersByRouteId, loaderContext) {
|
|
82
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
89
|
const loaderDatas = {};
|
|
84
90
|
if (!matches.length) {
|
|
85
91
|
return loaderDatas;
|
|
86
92
|
}
|
|
87
|
-
const appContext = getAppContext();
|
|
88
93
|
const createLoader = (match) => () => __awaiter(this, void 0, void 0, function* () {
|
|
89
94
|
const loaderFn = loadersByRouteId[match.route.id];
|
|
90
95
|
if (typeof loaderFn !== 'function') {
|
|
@@ -93,9 +98,7 @@ function runLoaders(matches, loadersByRouteId, { pathname, query, params, req, g
|
|
|
93
98
|
let res;
|
|
94
99
|
let error;
|
|
95
100
|
try {
|
|
96
|
-
const value = yield loaderFn(
|
|
97
|
-
params,
|
|
98
|
-
query, redirect: redirectHelper, error: errorHelper, appContext }, (req ? { req } : {})));
|
|
101
|
+
const value = yield loaderFn(loaderContext);
|
|
99
102
|
if (value === undefined) {
|
|
100
103
|
error = new Error(`You defined a loader for route "${match.route.path}" but didn't return ` +
|
|
101
104
|
`anything from your \`loader\` function. Please return a value or \`null\`.`);
|
package/lib/shared/router.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { matchPathname, rankRouteBranches, parseQuery, createRouter, createBrowserHistory, createHashHistory, createMemoryHistory } from '@shuvi/router';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ParsedQuery, IParams, IRouteRecord } from '@shuvi/router';
|
|
2
|
-
|
|
2
|
+
import { IRouter as IRouter_, IRoute, IRouteMatch, PathRecord } from '@shuvi/router';
|
|
3
|
+
export { IRoute, IRouteMatch, PathRecord };
|
|
3
4
|
export declare type IURLQuery = ParsedQuery;
|
|
4
5
|
export declare type IURLParams = IParams;
|
|
6
|
+
export declare type IRouter = IRouter_<IPageRouteRecord>;
|
|
5
7
|
export interface IPageRouteRecord extends IRouteRecord {
|
|
6
8
|
id: string;
|
|
7
9
|
path: string;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { IPluginInstance, IPluginHandlers, HookMap } from '@shuvi/hook';
|
|
2
2
|
import { CustomRuntimePluginHooks } from '@shuvi/runtime';
|
|
3
3
|
import { IAppContext } from './applicationTypes';
|
|
4
|
+
import { IRouter } from './routerTypes';
|
|
4
5
|
export declare type AppComponent = unknown;
|
|
6
|
+
export declare type AppContextCtx = {
|
|
7
|
+
router: IRouter;
|
|
8
|
+
};
|
|
5
9
|
declare const init: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext,
|
|
10
|
+
declare const appContext: import("@shuvi/hook").AsyncSeriesHook<IAppContext, AppContextCtx, void>;
|
|
7
11
|
declare const appComponent: import("@shuvi/hook").AsyncSeriesWaterfallHook<unknown, IAppContext>;
|
|
8
12
|
declare const dispose: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
13
|
export interface BuiltInRuntimePluginHooks extends HookMap {
|
|
10
14
|
init: typeof init;
|
|
11
|
-
appComponent: typeof appComponent;
|
|
12
15
|
appContext: typeof appContext;
|
|
16
|
+
appComponent: typeof appComponent;
|
|
13
17
|
dispose: typeof dispose;
|
|
14
18
|
}
|
|
15
19
|
export interface RuntimePluginHooks extends BuiltInRuntimePluginHooks, CustomRuntimePluginHooks {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/platform-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"node": ">= 16.0.0"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@shuvi/hook": "1.0.
|
|
86
|
+
"@shuvi/hook": "1.0.39",
|
|
87
87
|
"doura": "0.0.13",
|
|
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.
|
|
88
|
+
"@shuvi/router": "1.0.39",
|
|
89
|
+
"@shuvi/runtime": "1.0.39",
|
|
90
|
+
"@shuvi/shared": "1.0.39",
|
|
91
|
+
"@shuvi/toolpack": "1.0.39",
|
|
92
|
+
"@shuvi/utils": "1.0.39"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
-
"@shuvi/service": "1.0.
|
|
95
|
+
"@shuvi/service": "1.0.39"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@shuvi/service": "workspace:*",
|