Socket
Socket
Sign inDemoInstall

@modern-js/types

Package Overview
Dependencies
Maintainers
15
Versions
3265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modern-js/types - npm Package Compare versions

Comparing version 0.0.0-canary-20221102031626 to 0.0.0-canary-20221104083314

19

CHANGELOG.md
# @modern-js/types
## 0.0.0-canary-20221102031626
## 0.0.0-canary-20221104083314
### Patch Changes
## 1.21.1
- cc971eabf: refactor: move server plugin load logic in `@modern-js/core`
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
- 6bda14ed7: feat: refactor router with react-router@6.4
feat: 使用 react-router@6.4 重构路由模块
- 102d32e4b: feat(server): add `req` and `res` to SSR context
feat(server): 添加 `req` 和 `res` 到 SSR context 中
- 8b8e1bb57: feat: support nested routes
feat: 支持嵌套路由
- 3bbea92b2: feat: support Hook、Middleware new API
feat: 支持 Hook、Middleware 的新 API
## 1.21.0

@@ -23,0 +8,0 @@

@@ -1,3 +0,1 @@

import type { Merge } from 'type-fest';
import { InternalPlugins } from '../common';
import { ServerRoute } from '../server';

@@ -11,3 +9,2 @@

entry: string;
nestedRoutesEntry?: string;
isAutoMount?: boolean;

@@ -24,3 +21,3 @@ customBootstrap?: string | false;

*/
export type RouteLegacy = {
export interface Route {
path: string;

@@ -30,49 +27,6 @@ exact: boolean;

_component: string;
routes?: RouteLegacy[];
parent?: RouteLegacy;
};
routes?: Route[];
parent?: Route;
}
export type Route = Partial<{
caseSensitive: boolean;
path: string;
id: string;
loader: any;
action: any;
hasErrorBoundary: boolean;
shouldRevalidate: any;
handle: any;
index: boolean;
children: Route[] | undefined;
element: React.ReactNode | null;
errorElement: React.ReactNode | null;
}> & {
type: string;
};
export type NestedRoute = Merge<
Route,
{
type: 'nested';
parentId?: string;
children?: NestedRoute[];
childIds?: string[];
filename?: string;
_component?: string;
component?: string;
loading?: string;
error?: string;
}
>;
export type PageRoute = Merge<
Route,
{
type: 'page';
parent?: PageRoute;
_component: string;
component: string;
children?: PageRoute[];
}
>;
/**

@@ -96,3 +50,2 @@ * custom html partials.

serverConfigFile: string;
serverInternalPlugins: InternalPlugins;
ip?: string;

@@ -106,3 +59,7 @@ port?: number;

internalDirectory: string;
plugins: any[];
plugins: {
cli?: any;
server?: any;
serverPkg?: any;
}[];
entrypoints: Entrypoint[];

@@ -116,3 +73,1 @@ checkedEntries: string[];

}
export type { Merge } from 'type-fest';
export * from './server';
export * from './cli';
export * from './common';

19

package.json

@@ -14,3 +14,3 @@ {

],
"version": "0.0.0-canary-20221102031626",
"version": "0.0.0-canary-20221104083314",
"types": "./index.d.ts",

@@ -24,20 +24,9 @@ "exports": {

},
"typesVersions": {
"*": {
".": [
"./index.d.ts"
],
"hoist-non-react-statics": [
"./packages/hoist-non-react-statics.d.ts"
]
}
},
"devDependencies": {
"@scripts/build": "0.0.0-canary-20221102031626",
"@scripts/jest-config": "0.0.0-canary-20221102031626",
"@scripts/build": "0.0.0-canary-20221104083314",
"@scripts/jest-config": "0.0.0-canary-20221104083314",
"@types/jest": "^27",
"@types/node": "^14",
"http-proxy-middleware": "^2.0.4",
"jest": "^27",
"type-fest": "2.15.0"
"jest": "^27"
},

@@ -44,0 +33,0 @@ "sideEffects": false,

@@ -9,3 +9,3 @@ import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';

res: ServerResponse & { locals?: Record<string, any> };
res: ServerResponse;

@@ -68,3 +68,2 @@ params: Record<string, string>;

status: (code: number) => void;
locals: Record<string, any>;
};

@@ -93,7 +92,4 @@ redirection: { url?: string; status?: number };

cacheConfig?: any;
};
req: ModernServerContext['req'];
res: ModernServerContext['res'];
};
export interface ISAppContext {

@@ -100,0 +96,0 @@ appDirectory: string;

import { IncomingMessage, ServerResponse } from 'http';
import { ServerRoute as Route } from './route';
import { NextFunction } from './utils';
import { ModernServerContext } from './context';
export type CookieAPI = {
get: (key: string) => string;
set: (key: string, value: string) => void;
delete: (key: string) => void;
clear: () => void;
apply: () => void;
};
type Middleware = (
req: IncomingMessage,
res: ServerResponse,
next: NextFunction,
) => Promise<void>;
export interface ModernResponse {
get: (key: string) => string | number | string[] | undefined;
set: (key: string, value: string) => void;
status: (code: number) => void;
cookies: CookieAPI;
raw: (
body: string,
{ status, headers }: { status: number; headers: Record<string, any> },
) => void;
}
export interface ModernRequest {
host: string;
pathname: string;
query: Record<string, any>;
cookie: string;
cookies: Pick<CookieAPI, 'get'>;
headers: IncomingHttpHeaders;
}
export type HookContext = {
response: ModernResponse;
request: ModernRequest;
logger: Logger;
metrics?: Metrics;
export type TemplateAPI = {
get: () => Promise<string>;
set: (html: string) => void;
prependBody: (frag: string) => TemplateAPI;
prependHead: (frag: string) => TemplateAPI;
appendBody: (frag: string) => TemplateAPI;
appendHead: (frag: string) => TemplateAPI;
replace: (tag: string, frag: string) => TemplateAPI;
};
export type AfterMatchContext = HookContext & {
router: {
readonly current: string;
readonly url: string;
readonly status: number;
redirect: (url: string, status: number) => void;
rewrite: (entry: string) => void;
use: (entry: string) => void;
};
export type RouteAPI = {
cur: () => Route;
get: (entryName: string) => Route | undefined;
use: (entryName: string) => boolean;
};
export type AfterRenderContext = HookContext & {
template: {
set: (content: string) => void;
get: () => string;
prependHead: (fragment: string) => void;
appendHead: (fragment: string) => void;
prependBody: (fragment: string) => void;
appendBody: (fragment: string) => void;
};
type HookHandler<Context> = (ctx: Context, next: NextFunction) => Promise<void>;
type Hook<Context> = (fn: HookHandler<Context>) => void;
export type ModernServerHook = {
beforeMatch: Hook<ModernServerContext>;
afterMatch: Hook<ModernServerContext & { router: RouteAPI }>;
beforeRender: Hook<ModernServerContext>;
afterRender: Hook<ModernServerContext & { template: TemplateAPI }>;
};
export type MiddlewareContext = HookContext & {
response: ModernResponse & { locals: Record<string, any> };
source: {
req: IncomingMessage;
res: ServerResponse;
};
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc