@bleedingdev/modern-js-types 3.2.0-ultramodern.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ <p align="center">
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
+ </p>
4
+
5
+ <h1 align="center">Modern.js</h1>
6
+
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
14
+
15
+ ## Documentation
16
+
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
19
+
20
+ ## Contributing
21
+
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
+
24
+ ## License
25
+
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
package/cli/index.d.ts ADDED
@@ -0,0 +1,151 @@
1
+ import type { Config as JestConfigTypes } from '@jest/types';
2
+
3
+ export type JestConfig = JestConfigTypes.Config;
4
+
5
+ export interface TestConfig {
6
+ /**
7
+ * Decide which transformer will be used to compile file
8
+ * @default 'babel-jest'
9
+ */
10
+ transformer?: 'babel-jest' | 'ts-jest';
11
+
12
+ /**
13
+ * Original jest config
14
+ * Doc: https://jestjs.io/docs/configuration
15
+ */
16
+ jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
17
+ }
18
+
19
+ /**
20
+ * Bundle entrypoint
21
+ */
22
+ export interface Entrypoint {
23
+ entryName: string;
24
+ isMainEntry: boolean;
25
+ entry: string;
26
+ internalEntry?: string;
27
+ nestedRoutesEntry?: string;
28
+ pageRoutesEntry?: string;
29
+ isAutoMount?: boolean;
30
+ /**
31
+ * use src/{entryName}/entry.tsx to custom entry
32
+ */
33
+ customEntry?: boolean;
34
+
35
+ customServerEntry?: string | false;
36
+
37
+ fileSystemRoutes?: {
38
+ globalApp?: string | false;
39
+ routes?: any[];
40
+ };
41
+ absoluteEntryDir?: string;
42
+ /**
43
+ * use source.entries to custom entry
44
+ */
45
+ isCustomSourceEntry?: boolean;
46
+ }
47
+
48
+ /**
49
+ * file system routes.
50
+ */
51
+ export type RouteLegacy = {
52
+ path: string;
53
+ exact: boolean;
54
+ component: string;
55
+ _component: string;
56
+ routes?: RouteLegacy[];
57
+ parent?: RouteLegacy;
58
+ };
59
+
60
+ export interface Route {
61
+ caseSensitive?: boolean;
62
+ path?: string;
63
+ id?: string;
64
+ loader?: any;
65
+ action?: any;
66
+ hasErrorBoundary?: boolean;
67
+ shouldRevalidate?: any;
68
+ handle?: any;
69
+ index?: boolean;
70
+ children?: Route[] | undefined;
71
+ element?: React.ReactNode | null;
72
+ errorElement?: React.ReactNode | null;
73
+ type: string;
74
+ }
75
+
76
+ export type NestedRouteForCli = NestedRoute<string>;
77
+
78
+ export interface NestedRoute<T = string | (() => JSX.Element)> extends Route {
79
+ type: 'nested';
80
+ origin: 'file-system' | 'config';
81
+ // Route type to distinguish between page and layout routes
82
+ routeType?: 'page' | 'layout';
83
+ parentId?: string;
84
+ data?: string;
85
+ clientData?: string;
86
+ children?: NestedRoute<T>[];
87
+ filename?: string;
88
+ _component?: string;
89
+ component?: T;
90
+ lazyImport?: () => Promise<any>;
91
+ loading?: T;
92
+ error?: T;
93
+ isRoot?: boolean;
94
+ config?: string | Record<string, any>;
95
+ inValidSSRRoute?: boolean;
96
+ isClientComponent?: boolean;
97
+ params?: string[];
98
+ }
99
+
100
+ export interface PageRoute extends Route {
101
+ type: 'page';
102
+ parent?: PageRoute;
103
+ _component: string;
104
+ component: string;
105
+ children?: PageRoute[];
106
+ }
107
+
108
+ /**
109
+ * custom html partials.
110
+ */
111
+ export interface HtmlPartials {
112
+ top: string[];
113
+ head: string[];
114
+ body: string[];
115
+ }
116
+
117
+ export interface HtmlTemplates {
118
+ [name: string]: string;
119
+ }
120
+
121
+ export type SSGRouteOptions =
122
+ | string
123
+ | {
124
+ url: string;
125
+ output?: string;
126
+ headers?: Record<string, any>;
127
+ };
128
+
129
+ export type SSGSingleEntryOptions =
130
+ | boolean
131
+ | {
132
+ headers?: Record<string, any>;
133
+ routes?: SSGRouteOptions[];
134
+ };
135
+
136
+ export type SSGSingleEntryOptionsFactory = (
137
+ entryName: string,
138
+ ctx: { baseUrl?: string | string[] },
139
+ ) => SSGSingleEntryOptions;
140
+
141
+ export type SSGMultiEntryOptions = Record<
142
+ string,
143
+ SSGSingleEntryOptions | SSGSingleEntryOptionsFactory
144
+ >;
145
+
146
+ export type SSGConfig =
147
+ | boolean
148
+ | SSGSingleEntryOptions
149
+ | SSGSingleEntryOptionsFactory;
150
+
151
+ export type { Merge } from 'type-fest';
@@ -0,0 +1,16 @@
1
+ export * from './babel';
2
+ export * from './moduleSdk';
3
+
4
+ export type InternalPlugins = Record<
5
+ string,
6
+ string | { path: string; forced?: boolean }
7
+ >;
8
+
9
+ export type ServerPlugin = {
10
+ /** The plugin package.json's name */
11
+ name: string;
12
+
13
+ options?: Record<string, any>;
14
+ };
15
+
16
+ export type SSRMode = 'string' | 'stream' | false;
@@ -0,0 +1,101 @@
1
+ export type ModuleRuntimeLane =
2
+ | 'effect-first'
3
+ | 'tanstack-first'
4
+ | 'hono-compat'
5
+ | 'react-router-compat';
6
+
7
+ export type ModuleLifecycleHook =
8
+ | 'registerRoutes'
9
+ | 'registerCapabilities'
10
+ | 'registerMigrations'
11
+ | 'registerEventContracts';
12
+
13
+ export type ModulePolicyHook =
14
+ | 'authorize'
15
+ | 'enforceTenantScope'
16
+ | 'validateOperationContext'
17
+ | 'validateEventEnvelope';
18
+
19
+ export type ModuleObservabilityHook =
20
+ | 'emitBusinessMetric'
21
+ | 'emitAuditEvent'
22
+ | 'emitTraceContext'
23
+ | 'emitEventContractViolation';
24
+
25
+ export type ModuleObservabilitySignal = 'metrics' | 'audit' | 'trace';
26
+ export type ModuleComplianceFlagName =
27
+ | keyof ModuleComplianceFlags
28
+ | (string & {});
29
+ export type ModuleLifecycleHookName = ModuleLifecycleHook | (string & {});
30
+ export type ModulePolicyHookName = ModulePolicyHook | (string & {});
31
+ export type ModuleObservabilityHookName =
32
+ | ModuleObservabilityHook
33
+ | (string & {});
34
+ export type ModuleObservabilitySignalName =
35
+ | ModuleObservabilitySignal
36
+ | (string & {});
37
+
38
+ export interface ModuleComplianceFlags {
39
+ usesSdkContracts: boolean;
40
+ usesPolicyMiddleware: boolean;
41
+ usesObservabilityHooks: boolean;
42
+ }
43
+
44
+ export interface ModuleSdkSharedRequirements {
45
+ requiredManifestFields: string[];
46
+ requiredComplianceFlags: ModuleComplianceFlagName[];
47
+ requiredObservabilitySignals: ModuleObservabilitySignalName[];
48
+ requiredLifecycleHooks: ModuleLifecycleHookName[];
49
+ requiredPolicyHooks: ModulePolicyHookName[];
50
+ requiredObservabilityHooks: ModuleObservabilityHookName[];
51
+ forbiddenCodePatterns: string[];
52
+ }
53
+
54
+ export interface ModuleSdkProfileContract {
55
+ requiredManifestFields?: string[];
56
+ requiredComplianceFlags?: ModuleComplianceFlagName[];
57
+ requiredObservabilitySignals?: ModuleObservabilitySignalName[];
58
+ requiredLifecycleHooks?: ModuleLifecycleHookName[];
59
+ requiredPolicyHooks?: ModulePolicyHookName[];
60
+ requiredObservabilityHooks?: ModuleObservabilityHookName[];
61
+ forbiddenCodePatterns?: string[];
62
+ }
63
+
64
+ export interface ModuleSdkContracts {
65
+ schemaVersion: number;
66
+ compatibilityLanes: ModuleRuntimeLane[];
67
+ sharedRequirements: ModuleSdkSharedRequirements;
68
+ profiles?: Record<string, ModuleSdkProfileContract>;
69
+ }
70
+
71
+ export interface ModuleSdkManifest {
72
+ moduleId: string;
73
+ profile?: string;
74
+ version: string;
75
+ runtime: ModuleRuntimeLane;
76
+ sourceDir: string;
77
+ lifecycleHooks: ModuleLifecycleHookName[];
78
+ policyHooks: ModulePolicyHookName[];
79
+ observability: {
80
+ signals: ModuleObservabilitySignalName[];
81
+ hooks: ModuleObservabilityHookName[];
82
+ };
83
+ compliance: ModuleComplianceFlags & Record<string, boolean>;
84
+ }
85
+
86
+ export interface ModuleEventContract {
87
+ name: string;
88
+ version: number;
89
+ schemaHash: string;
90
+ producerModuleId: string;
91
+ description?: string;
92
+ }
93
+
94
+ export interface ModuleEventEnvelope<Payload = unknown> {
95
+ name: string;
96
+ version: number;
97
+ schemaHash: string;
98
+ timestamp: number;
99
+ payload: Payload;
100
+ meta?: Record<string, unknown>;
101
+ }
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './cli';
2
+ export * from './common';
3
+ export * from './server';
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@bleedingdev/modern-js-types",
3
+ "description": "A Progressive React Framework for modern web development.",
4
+ "homepage": "https://github.com/BleedingDev/ultramodern.js#readme",
5
+ "bugs": {
6
+ "url": "https://github.com/BleedingDev/ultramodern.js/issues"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/BleedingDev/ultramodern.js.git",
11
+ "directory": "packages/toolkit/types"
12
+ },
13
+ "license": "MIT",
14
+ "keywords": [
15
+ "react",
16
+ "framework",
17
+ "modern",
18
+ "modern.js"
19
+ ],
20
+ "version": "3.2.0-ultramodern.0",
21
+ "types": "./index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "default": "./index.d.ts"
26
+ },
27
+ "./server": {
28
+ "types": "./server/index.d.ts",
29
+ "default": "./server/index.d.ts"
30
+ },
31
+ "./cli": {
32
+ "types": "./cli/index.d.ts",
33
+ "default": "./cli/index.d.ts"
34
+ }
35
+ },
36
+ "typesVersions": {
37
+ "*": {
38
+ ".": [
39
+ "./index.d.ts"
40
+ ],
41
+ "server": [
42
+ "./server/index.d.ts"
43
+ ],
44
+ "cli": [
45
+ "./cli/index.d.ts"
46
+ ]
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@types/babel__core": "^7.20.5",
51
+ "@types/node": "^25.8.0",
52
+ "http-proxy-middleware": "^4.0.0",
53
+ "type-fest": "5.6.0"
54
+ },
55
+ "sideEffects": false,
56
+ "publishConfig": {
57
+ "registry": "https://registry.npmjs.org/",
58
+ "access": "public"
59
+ },
60
+ "scripts": {
61
+ "test": "rstest --passWithNoTests"
62
+ },
63
+ "main": ""
64
+ }
@@ -0,0 +1,71 @@
1
+ interface REACT_STATICS {
2
+ childContextTypes: true;
3
+ contextType: true;
4
+ contextTypes: true;
5
+ defaultProps: true;
6
+ displayName: true;
7
+ getDefaultProps: true;
8
+ getDerivedStateFromError: true;
9
+ getDerivedStateFromProps: true;
10
+ mixins: true;
11
+ propTypes: true;
12
+ type: true;
13
+ }
14
+
15
+ interface KNOWN_STATICS {
16
+ name: true;
17
+ length: true;
18
+ prototype: true;
19
+ caller: true;
20
+ callee: true;
21
+ arguments: true;
22
+ arity: true;
23
+ }
24
+
25
+ interface MEMO_STATICS {
26
+ $$typeof: true;
27
+ compare: true;
28
+ defaultProps: true;
29
+ displayName: true;
30
+ propTypes: true;
31
+ type: true;
32
+ }
33
+
34
+ interface FORWARD_REF_STATICS {
35
+ $$typeof: true;
36
+ render: true;
37
+ defaultProps: true;
38
+ displayName: true;
39
+ propTypes: true;
40
+ }
41
+ declare namespace hoistNonReactStatics {
42
+ type NonReactStatics<
43
+ S extends React.ComponentType<any>,
44
+ C extends {
45
+ [key: string]: true;
46
+ } = {},
47
+ > = {
48
+ [key in Exclude<
49
+ keyof S,
50
+ S extends React.MemoExoticComponent<any>
51
+ ? keyof MEMO_STATICS | keyof C
52
+ : S extends React.ForwardRefExoticComponent<any>
53
+ ? keyof FORWARD_REF_STATICS | keyof C
54
+ : keyof REACT_STATICS | keyof KNOWN_STATICS | keyof C
55
+ >]: S[key];
56
+ };
57
+ }
58
+ declare module 'hoist-non-react-statics' {
59
+ declare function hoistNonReactStatics<
60
+ T extends React.ComponentType<any>,
61
+ S extends React.ComponentType<any>,
62
+ C extends {
63
+ [key: string]: true;
64
+ } = {},
65
+ >(
66
+ TargetComponent: T,
67
+ SourceComponent: S,
68
+ customStatic?: C,
69
+ ): T & hoistNonReactStatics.NonReactStatics<S, C>;
70
+ export default hoistNonReactStatics;
71
+ }
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from '@rstest/core';
2
+
3
+ export default defineConfig({
4
+ globals: true,
5
+ });
@@ -0,0 +1 @@
1
+ export type HttpMethodDecider = 'functionName' | 'inputParams';
@@ -0,0 +1,107 @@
1
+ import type { SSRMode } from 'common';
2
+ import type {
3
+ Server as HttpServer,
4
+ IncomingHttpHeaders,
5
+ IncomingMessage,
6
+ ServerResponse,
7
+ } from 'http';
8
+ import type qs from 'querystring';
9
+ import type { Logger, Metrics, Reporter, ServerTiming } from './utils';
10
+
11
+ export interface RequestPayload {
12
+ [key: string]: unknown;
13
+ }
14
+
15
+ export interface ModernServerContext {
16
+ req: IncomingMessage;
17
+
18
+ res: ServerResponse & { locals?: Record<string, any> };
19
+
20
+ params: Record<string, string>;
21
+
22
+ logger: Logger;
23
+
24
+ metrics: Metrics;
25
+
26
+ reporter: Reporter;
27
+
28
+ serverTiming: ServerTiming;
29
+
30
+ setParams: (params: Record<string, string>) => void;
31
+
32
+ getReqHeader: (key: string) => void;
33
+
34
+ headers: IncomingHttpHeaders;
35
+
36
+ method: string;
37
+
38
+ url: string;
39
+
40
+ host: string;
41
+
42
+ protocol: string;
43
+
44
+ origin: string;
45
+
46
+ href: string;
47
+
48
+ path: string;
49
+
50
+ querystring: string;
51
+
52
+ query: qs.ParsedUrlQuery;
53
+
54
+ status: number;
55
+
56
+ serverData: Record<string, any>;
57
+
58
+ resHasHandled: () => boolean;
59
+
60
+ error: (dig: string, e: Error | string = '') => void;
61
+
62
+ setServerData: (key: string, value: any) => void;
63
+ }
64
+
65
+ export interface BaseResponseLike {
66
+ setHeader: (key: string, value: string) => void;
67
+ status: (code: number) => void;
68
+ locals: Record<string, any>;
69
+ }
70
+
71
+ export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
72
+ baseUrl: string;
73
+ request: {
74
+ params: Record<string, string>;
75
+ pathname: string;
76
+ query: Record<string, string>;
77
+ headers: IncomingHttpHeaders;
78
+ host: string;
79
+ url: string;
80
+ referer?: string;
81
+ userAgent?: string;
82
+ cookie?: string;
83
+ cookieMap?: Record<string, string>;
84
+ };
85
+ response: BaseResponseLike;
86
+ loadableStats: Record<string, any>;
87
+ routeManifest?: Record<string, any>;
88
+ template: string;
89
+ entryName: string;
90
+ loaderContext: Map<string, unknown>;
91
+ logger: Logger;
92
+ serverTiming: ServerTiming;
93
+ reporter?: Reporter;
94
+ cacheConfig?: any;
95
+
96
+ enableUnsafeCtx?: boolean;
97
+
98
+ unsafeHeaders?: string[];
99
+
100
+ nonce?: string;
101
+ /** SSR type */
102
+ mode?: SSRMode;
103
+ };
104
+
105
+ export interface ServerInitHookContext {
106
+ app?: HttpServer;
107
+ }
@@ -0,0 +1,17 @@
1
+ import type { NodeRequest, NodeResponse } from '@modern-js/server-core/node';
2
+ import type { DevProxyOptions, NextFunction } from './utils';
3
+
4
+ export type DevServerHttpsOptions = boolean | { key: string; cert: string };
5
+
6
+ export type RequestHandler = (
7
+ req: NodeRequest,
8
+ res: NodeResponse,
9
+ next: NextFunction,
10
+ ) => void;
11
+
12
+ export type ExposeServerApis = {
13
+ sockWrite: (
14
+ type: string,
15
+ data?: string | boolean | Record<string, any>,
16
+ ) => void;
17
+ };
@@ -0,0 +1,97 @@
1
+ import type {
2
+ IncomingHttpHeaders,
3
+ IncomingMessage,
4
+ ServerResponse,
5
+ } from 'http';
6
+ import type { ServerRoute } from './route';
7
+ import type { NodeRequest, NodeResponse } from './server';
8
+ import type { Logger, Metrics, Reporter } from './utils';
9
+
10
+ export type CookieAPI = {
11
+ /**
12
+ * @deprecated Using set empty cookie instead.
13
+ */
14
+ delete?: (key: string) => void;
15
+ get?: (key: string) => string;
16
+ set: (key: string, value: string, options?: any) => void;
17
+ clear: () => void;
18
+ };
19
+
20
+ export interface ModernResponse {
21
+ get: (key: string) => string | number | string[] | undefined;
22
+ set: (key: string, value: string | number) => void;
23
+ status: (code: number) => void;
24
+ getStatus: () => number;
25
+ cookies: CookieAPI;
26
+ raw: (
27
+ body: string,
28
+ options?: { status?: number; headers?: Record<string, any> },
29
+ ) => void;
30
+ }
31
+
32
+ export interface ModernRequest {
33
+ url: string;
34
+ host: string;
35
+ pathname: string;
36
+ query: Record<string, any>;
37
+ cookie: string;
38
+ cookies: Pick<CookieAPI, 'get'>;
39
+ headers: IncomingHttpHeaders;
40
+ }
41
+
42
+ export type HookContext = {
43
+ response: ModernResponse;
44
+ request: ModernRequest;
45
+ logger: Logger;
46
+ metrics?: Metrics;
47
+ };
48
+
49
+ export type AfterMatchContext = HookContext & {
50
+ router: {
51
+ readonly current: string;
52
+ readonly url: string;
53
+ readonly status: number;
54
+ redirect: (url: string, status?: number) => void;
55
+ rewrite: (entry: string) => void;
56
+ use: (entry: string) => void;
57
+ };
58
+ };
59
+
60
+ export type AfterRenderContext = HookContext & {
61
+ route?: Partial<
62
+ Pick<
63
+ ServerRoute,
64
+ 'entryName' | 'bundle' | 'isSPA' | 'isSSR' | 'urlPath' | 'entryPath'
65
+ >
66
+ >;
67
+ template: {
68
+ set: (content: string) => void;
69
+ // FIXME: break change
70
+ // get: () => Promise<string>;
71
+ get: () => string;
72
+ prependHead: (fragment: string) => void;
73
+ appendHead: (fragment: string) => void;
74
+ prependBody: (fragment: string) => void;
75
+ appendBody: (fragment: string) => void;
76
+ };
77
+ };
78
+
79
+ export type AfterStreamingRenderContext = HookContext & {
80
+ route?: Partial<
81
+ Pick<
82
+ ServerRoute,
83
+ 'entryName' | 'bundle' | 'isSPA' | 'isSSR' | 'urlPath' | 'entryPath'
84
+ >
85
+ >;
86
+ chunk: string;
87
+ };
88
+
89
+ export type MiddlewareContext<T extends 'worker' | 'node' = 'node'> =
90
+ HookContext & {
91
+ reporter?: Reporter;
92
+ response: ModernResponse & { locals: Record<string, any> };
93
+ source: {
94
+ req: T extends 'worker' ? Request : NodeRequest;
95
+ res: T extends 'worker' ? ModernResponse : NodeResponse;
96
+ };
97
+ };
@@ -0,0 +1,10 @@
1
+ export * from './bff';
2
+ export * from './context';
3
+ export * from './devServer';
4
+ export * from './hook';
5
+ export * from './middleware';
6
+ export * from './monitor';
7
+ export * from './route';
8
+ export * from './rsc';
9
+ export * from './server';
10
+ export * from './utils';
@@ -0,0 +1,56 @@
1
+ /** Monitor Events */
2
+ export type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
3
+
4
+ export interface LogEvent {
5
+ type: 'log';
6
+ payload: {
7
+ level: LogLevel;
8
+ message: string;
9
+ args?: any[];
10
+ };
11
+ }
12
+
13
+ export interface TimingEvent {
14
+ type: 'timing';
15
+ payload: {
16
+ name: string;
17
+ dur: number;
18
+ desc?: string;
19
+ tags?: Record<string, any>;
20
+ args?: any[];
21
+ };
22
+ }
23
+
24
+ export interface CounterEvent {
25
+ type: 'counter';
26
+ payload: {
27
+ name: string;
28
+ tags?: Record<string, any>;
29
+ args?: any[];
30
+ };
31
+ }
32
+
33
+ export type MonitorEvent = LogEvent | TimingEvent | CounterEvent;
34
+
35
+ export type CoreMonitor = (event: MonitorEvent) => void;
36
+
37
+ export interface Monitors {
38
+ push(monitor: CoreMonitor): void;
39
+
40
+ // 日志事件
41
+ error(message: string, ...args: any[]): void;
42
+ warn(message: string, ...args: any[]): void;
43
+ debug(message: string, ...args: any[]): void;
44
+ info(message: string, ...args: any[]): void;
45
+ trace(message: string, ...args: any[]): void;
46
+
47
+ // 打点事件
48
+ timing(
49
+ name: string,
50
+ dur: number,
51
+ desc?: string,
52
+ tags?: Record<string, any>,
53
+ ...args: any[]
54
+ ): void;
55
+ counter(name: string, tags?: Record<string, any>, ...args: any[]): void;
56
+ }
@@ -0,0 +1,24 @@
1
+ export interface ServerRoute {
2
+ // modern js web entry name
3
+ entryName?: string;
4
+ // the url path for request match
5
+ urlPath: string;
6
+ // the default asset to response to route
7
+ entryPath: string;
8
+ // if route is spa page
9
+ isSPA?: boolean;
10
+ // if route is ssr page
11
+ isSSR?: boolean;
12
+ // if route is rsc page
13
+ isRSC?: boolean;
14
+ // if route is stream response
15
+ isStream?: boolean;
16
+ // if route is api service
17
+ isApi?: boolean;
18
+ // worker js bundle for ssr page
19
+ worker?: string;
20
+ // ssr js bundle for ssr page
21
+ bundle?: string;
22
+ // response header for routes
23
+ responseHeaders?: Record<string, unknown>;
24
+ }
@@ -0,0 +1,54 @@
1
+ export type ImportManifestEntry = {
2
+ id: string | number;
3
+ chunks: (string | number)[];
4
+ styles?: string[];
5
+ name: string;
6
+ };
7
+
8
+ export interface ClientReference {
9
+ readonly id: string | number;
10
+ readonly exportName: string;
11
+ ssrId?: string | number;
12
+ }
13
+
14
+ export interface ClientManifest {
15
+ [id: string]: ImportManifestEntry;
16
+ }
17
+
18
+ export interface ServerManifest {
19
+ [id: string]: ImportManifestEntry;
20
+ }
21
+
22
+ export interface ServerReferencesModuleInfo {
23
+ readonly exportNames: string[];
24
+ moduleId?: string | number;
25
+ }
26
+
27
+ export type ClientReferencesMap = Map<string, ClientReference[]>;
28
+
29
+ export type ServerReferencesMap = Map<string, ServerReferencesModuleInfo>;
30
+
31
+ export type ModuleLoading = null | {
32
+ prefix: string;
33
+ crossOrigin?: 'use-credentials' | '';
34
+ };
35
+
36
+ export type SSRModuleMap = {
37
+ [clientId: string]: {
38
+ [clientExportName: string]: ImportManifestEntry;
39
+ };
40
+ };
41
+
42
+ export type SSRManifest = {
43
+ moduleMap: SSRModuleMap;
44
+ moduleLoading: ModuleLoading;
45
+ styles: string[];
46
+ };
47
+
48
+ export type ServerManifest = {
49
+ [id: string]: ImportManifestEntry;
50
+ };
51
+
52
+ export type ClientManifest = {
53
+ [id: string]: ImportManifestEntry;
54
+ };
@@ -0,0 +1,5 @@
1
+ import type { IncomingMessage, ServerResponse } from 'http';
2
+ import type { Http2ServerRequest, Http2ServerResponse } from 'http2';
3
+
4
+ export type NodeRequest = IncomingMessage | Http2ServerRequest;
5
+ export type NodeResponse = ServerResponse | Http2ServerResponse;
@@ -0,0 +1,138 @@
1
+ import type { Http2ServerRequest } from 'node:http2';
2
+ import type { IncomingMessage, ServerResponse } from 'http';
3
+ import type {
4
+ Filter as ProxyFilter,
5
+ Options as ProxyOptions,
6
+ } from 'http-proxy-middleware';
7
+ import type { NodeRequest } from './server';
8
+ export interface Metrics {
9
+ emitCounter: (
10
+ name: string,
11
+ value: number,
12
+ prefix?: string,
13
+ tags?: Record<string, any>,
14
+ ) => void;
15
+ emitTimer: (
16
+ name: string,
17
+ value: number,
18
+ prefix?: string,
19
+ tags?: Record<string, any>,
20
+ ) => void;
21
+ }
22
+
23
+ type LoggerFunction = (message: string, ...args: any[]) => void;
24
+ export interface Logger {
25
+ error: LoggerFunction;
26
+ info: LoggerFunction;
27
+ warn: LoggerFunction;
28
+ debug: LoggerFunction;
29
+ }
30
+
31
+ export interface ServerTiming {
32
+ addServeTiming: (name: string, dur: number, decs?: string) => this;
33
+ }
34
+
35
+ export type Reporter<C = any> = {
36
+ sessionId?: string;
37
+ userId?: string;
38
+ client?: C;
39
+
40
+ init: (payload: { entryName: string }) => void | Promise<void>;
41
+
42
+ reportError: (
43
+ content: string,
44
+ e: Error,
45
+ extra?: Record<string, string | number>,
46
+ ) => void;
47
+
48
+ reportTiming: (
49
+ name: string,
50
+ value: number,
51
+ extra?: Record<string, string>,
52
+ ) => void;
53
+
54
+ reportInfo: (
55
+ content: string,
56
+ extra?: Record<string, string | number>,
57
+ ) => void;
58
+
59
+ reportWarn: (
60
+ content: string,
61
+ extra?: Record<string, string | number>,
62
+ ) => void;
63
+ };
64
+
65
+ export type NextFunction = () => void;
66
+
67
+ export type ProxyDetail = ProxyOptions & {
68
+ bypass?: (
69
+ req: IncomingMessage,
70
+ res: ServerResponse,
71
+ proxyOptions: DevProxyOptions,
72
+ ) => string | undefined | null | false;
73
+ context?: ProxyFilter;
74
+ };
75
+
76
+ export type DevProxyOptions =
77
+ | Record<string, string>
78
+ | Record<string, ProxyDetail>
79
+ | ProxyDetail[]
80
+ | ProxyDetail;
81
+
82
+ export type CacheControl = {
83
+ /**
84
+ * The maxAge like http cache-control: max-age.
85
+ *
86
+ * It refers to the cache validation time, measured in (ms).
87
+ */
88
+ maxAge: number;
89
+
90
+ /**
91
+ * The staleWhileRevalidate reference to http header cache-control: stale-while-revalidate.
92
+ *
93
+ * It means that the cache is stale but can still be used directly while asynchronously revalidating it, measured in (ms).
94
+ */
95
+ staleWhileRevalidate: number;
96
+
97
+ /**
98
+ * Specify a custom cache key yourself.
99
+ *
100
+ * The custom key will override the key used by default.
101
+ */
102
+ customKey?: string | ((pathname: string) => string);
103
+ };
104
+
105
+ export type CacheOptionProvider = (
106
+ req: NodeRequest,
107
+ ) => Promise<CacheControl | false> | CacheControl | false;
108
+
109
+ export type CacheOption =
110
+ | false
111
+ | CacheOptionProvider
112
+ | CacheControl
113
+ | Record<string, CacheControl | CacheOptionProvider>;
114
+
115
+ export interface Container<K = string, V = string> {
116
+ /**
117
+ * Returns a specified element from the container. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Container.
118
+ * @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
119
+ */
120
+ get: (key: K) => Promise<V | undefined>;
121
+
122
+ /**
123
+ * Adds a new element with a specified key and value to the container. If an element with the same key already exists, the element will be updated.
124
+ */
125
+ set: (key: K, value: V, options?: { ttl?: number }) => Promise<this>;
126
+
127
+ /**
128
+ * @returns boolean indicating whether an element with the specified key exists or not.
129
+ */
130
+ has: (key: K) => Promise<boolean>;
131
+
132
+ /**
133
+ * @returns true if an element in the container existed and has been removed, or false if the element does not exist.
134
+ */
135
+ delete: (key: K) => Promise<boolean>;
136
+
137
+ forEach?: (callbackFn: (v: V, k: K, container: this) => void) => void;
138
+ }