@modern-js/types
Advanced tools
Comparing version 0.0.0-canary-20221025140606 to 0.0.0-canary-20221026041443
# @modern-js/types | ||
## 0.0.0-canary-20221025140606 | ||
## 0.0.0-canary-20221026041443 | ||
### Patch Changes | ||
- f51c59ad: feat: remove node internal package like fs or path which import by ssr runtime | ||
- 3ee9d6d50: feat: remove node internal package like fs or path which import by ssr runtime | ||
feat: 删除在 ssr runtime 中引用的 node 内部包 | ||
- cc971eabf: refactor: move server plugin load logic in `@modern-js/core` | ||
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑 | ||
- 8b8e1bb57: feat: support nested routes | ||
feat: 支持嵌套路由 | ||
- 3bbea92b2: feat: support Hook、Middleware new API | ||
feat: 支持 Hook、Middleware 的新 API | ||
@@ -10,0 +16,0 @@ ## 1.20.1 |
@@ -0,1 +1,3 @@ | ||
import type { Merge } from 'type-fest'; | ||
import { InternalPlugins } from '../common'; | ||
import { ServerRoute } from '../server'; | ||
@@ -9,2 +11,3 @@ | ||
entry: string; | ||
nestedRoutesEntry?: string; | ||
isAutoMount?: boolean; | ||
@@ -21,3 +24,3 @@ customBootstrap?: string | false; | ||
*/ | ||
export interface Route { | ||
export type RouteLegacy = { | ||
path: string; | ||
@@ -27,6 +30,49 @@ exact: boolean; | ||
_component: string; | ||
routes?: Route[]; | ||
parent?: Route; | ||
} | ||
routes?: RouteLegacy[]; | ||
parent?: RouteLegacy; | ||
}; | ||
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[]; | ||
} | ||
>; | ||
/** | ||
@@ -50,2 +96,3 @@ * custom html partials. | ||
serverConfigFile: string; | ||
serverInternalPlugins: InternalPlugins; | ||
ip?: string; | ||
@@ -59,7 +106,3 @@ port?: number; | ||
internalDirectory: string; | ||
plugins: { | ||
cli?: any; | ||
server?: any; | ||
serverPkg?: any; | ||
}[]; | ||
plugins: any[]; | ||
entrypoints: Entrypoint[]; | ||
@@ -73,1 +116,3 @@ checkedEntries: string[]; | ||
} | ||
export type { Merge } from 'type-fest'; |
export * from './server'; | ||
export * from './cli'; | ||
export * from './common'; |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.0.0-canary-20221025140606", | ||
"version": "0.0.0-canary-20221026041443", | ||
"types": "./index.d.ts", | ||
@@ -24,9 +24,20 @@ "exports": { | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
".": [ | ||
"./index.d.ts" | ||
], | ||
"hoist-non-react-statics": [ | ||
"./packages/hoist-non-react-statics.d.ts" | ||
] | ||
} | ||
}, | ||
"devDependencies": { | ||
"@scripts/build": "1.20.1", | ||
"@scripts/jest-config": "1.20.1", | ||
"@scripts/build": "0.0.0-canary-20221026041443", | ||
"@scripts/jest-config": "0.0.0-canary-20221026041443", | ||
"@types/jest": "^27", | ||
"@types/node": "^14", | ||
"http-proxy-middleware": "^2.0.4", | ||
"jest": "^27" | ||
"jest": "^27", | ||
"type-fest": "2.15.0" | ||
}, | ||
@@ -33,0 +44,0 @@ "sideEffects": false, |
@@ -9,3 +9,3 @@ import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http'; | ||
res: ServerResponse; | ||
res: ServerResponse & { locals?: Record<string, any> }; | ||
@@ -68,2 +68,3 @@ params: Record<string, string>; | ||
status: (code: number) => void; | ||
locals: Record<string, any>; | ||
}; | ||
@@ -93,3 +94,2 @@ redirection: { url?: string; status?: number }; | ||
}; | ||
export interface ISAppContext { | ||
@@ -96,0 +96,0 @@ appDirectory: string; |
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { ServerRoute as Route } from './route'; | ||
import { NextFunction } from './utils'; | ||
import { ModernServerContext } from './context'; | ||
type Middleware = ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
next: NextFunction, | ||
) => Promise<void>; | ||
export type CookieAPI = { | ||
get: (key: string) => string; | ||
set: (key: string, value: string) => void; | ||
delete: (key: string) => void; | ||
clear: () => void; | ||
apply: () => void; | ||
}; | ||
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 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 RouteAPI = { | ||
cur: () => Route; | ||
get: (entryName: string) => Route | undefined; | ||
use: (entryName: string) => boolean; | ||
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; | ||
}; | ||
}; | ||
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 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; | ||
}; | ||
}; | ||
export type MiddlewareContext = HookContext & { | ||
response: ModernResponse & { locals: Record<string, any> }; | ||
source: { | ||
req: IncomingMessage; | ||
res: ServerResponse; | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26249
14
442
7