@modern-js/types 2.49.4 → 2.51.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/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.4",
18
+ "version": "2.51.0",
19
19
  "types": "./index.d.ts",
20
20
  "exports": {
21
21
  ".": {
@@ -45,8 +45,8 @@
45
45
  "http-proxy-middleware": "^2.0.4",
46
46
  "jest": "^29",
47
47
  "type-fest": "2.15.0",
48
- "@scripts/build": "2.49.4",
49
- "@scripts/jest-config": "2.49.4"
48
+ "@scripts/build": "2.51.0",
49
+ "@scripts/jest-config": "2.51.0"
50
50
  },
51
51
  "sideEffects": false,
52
52
  "publishConfig": {
@@ -8,6 +8,10 @@ import qs from 'querystring';
8
8
  import type { SSRMode } from 'common';
9
9
  import { Metrics, Logger, Reporter, ServerTiming } from './utils';
10
10
 
11
+ export interface RequestPayload {
12
+ [key: string]: unknown;
13
+ }
14
+
11
15
  export interface ModernServerContext {
12
16
  req: IncomingMessage;
13
17
 
@@ -79,6 +83,7 @@ export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
79
83
  routeManifest?: Record<string, any>;
80
84
  template: string;
81
85
  entryName: string;
86
+ loaderContext: Map<string, unknown>;
82
87
  logger: Logger;
83
88
  serverTiming: ServerTiming;
84
89
  reporter?: Reporter;
package/server/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './utils';
4
4
  export * from './route';
5
5
  export * from './bff';
6
6
  export * from './devServer';
7
+ export * from './middleware';
@@ -0,0 +1,39 @@
1
+ import { RequestPayload } from './context';
2
+
3
+ interface Set<V extends Record<string>> {
4
+ // eslint-disable-next-line @typescript-eslint/prefer-function-type
5
+ <Key extends keyof V>(key: Key, value: V[Key]): void;
6
+ }
7
+
8
+ interface Get<V extends Record<string, unknown>> {
9
+ // eslint-disable-next-line @typescript-eslint/prefer-function-type
10
+ <Key extends keyof V>(key: Key): V[Key];
11
+ }
12
+
13
+ type Body = ReadableStream | ArrayBuffer | string | null;
14
+
15
+ export type UnstableMiddlewareContext<
16
+ V extends Record<string, unknown> = Record<string, unknown>,
17
+ > = {
18
+ request: Request;
19
+ response: Response;
20
+ get: Get<V & RequestPayload>;
21
+ set: Set<V & RequestPayload>;
22
+ header: (name: string, value: string, options?: { append?: boolean }) => void;
23
+ status: (code: number) => void;
24
+ redirect: (location: string, status?: number) => Response;
25
+ body: (data: Body, init?: ResponseInit) => Response;
26
+ html: (
27
+ data: string | Promise<string>,
28
+ init?: ResponseInit,
29
+ ) => Response | Promise<Response>;
30
+ };
31
+
32
+ export type UnstableNext = () => Promise<void>;
33
+
34
+ export type UnstableMiddleware<
35
+ V extends Record<string, unknown> = Record<string, unknown>,
36
+ > = (
37
+ c: UnstableMiddlewareContext<V>,
38
+ next: UnstableNext,
39
+ ) => Promise<void | Response>;