@ripple-ts/vite-plugin 0.2.210 → 0.2.211
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/CHANGELOG.md +2 -0
- package/package.json +2 -2
- package/src/index.js +368 -4
- package/src/routes.js +70 -0
- package/src/server/middleware.js +126 -0
- package/src/server/production.js +266 -0
- package/src/server/render-route.js +232 -0
- package/src/server/router.js +122 -0
- package/src/server/server-route.js +46 -0
- package/types/index.d.ts +103 -0
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,112 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
|
|
3
3
|
declare module '@ripple-ts/vite-plugin' {
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Plugin exports
|
|
6
|
+
// ============================================================================
|
|
7
|
+
|
|
4
8
|
export function ripple(options?: RipplePluginOptions): Plugin[];
|
|
9
|
+
export function defineConfig(options: RippleConfigOptions): RippleConfigOptions;
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Route classes
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
export class RenderRoute {
|
|
16
|
+
readonly type: 'render';
|
|
17
|
+
path: string;
|
|
18
|
+
entry: string;
|
|
19
|
+
layout?: string;
|
|
20
|
+
before: Middleware[];
|
|
21
|
+
constructor(options: RenderRouteOptions);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ServerRoute {
|
|
25
|
+
readonly type: 'server';
|
|
26
|
+
path: string;
|
|
27
|
+
methods: string[];
|
|
28
|
+
handler: RouteHandler;
|
|
29
|
+
before: Middleware[];
|
|
30
|
+
after: Middleware[];
|
|
31
|
+
constructor(options: ServerRouteOptions);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type Route = RenderRoute | ServerRoute;
|
|
35
|
+
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Route options
|
|
38
|
+
// ============================================================================
|
|
39
|
+
|
|
40
|
+
export interface RenderRouteOptions {
|
|
41
|
+
/** URL path pattern (e.g., '/', '/posts/:id', '/docs/*slug') */
|
|
42
|
+
path: string;
|
|
43
|
+
/** Path to the Ripple component entry file */
|
|
44
|
+
entry: string;
|
|
45
|
+
/** Path to the layout component (wraps the entry) */
|
|
46
|
+
layout?: string;
|
|
47
|
+
/** Middleware to run before rendering */
|
|
48
|
+
before?: Middleware[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ServerRouteOptions {
|
|
52
|
+
/** URL path pattern (e.g., '/api/hello', '/api/posts/:id') */
|
|
53
|
+
path: string;
|
|
54
|
+
/** HTTP methods to handle (default: ['GET']) */
|
|
55
|
+
methods?: string[];
|
|
56
|
+
/** Request handler that returns a Response */
|
|
57
|
+
handler: RouteHandler;
|
|
58
|
+
/** Middleware to run before the handler */
|
|
59
|
+
before?: Middleware[];
|
|
60
|
+
/** Middleware to run after the handler */
|
|
61
|
+
after?: Middleware[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Context and middleware
|
|
66
|
+
// ============================================================================
|
|
67
|
+
|
|
68
|
+
export interface Context {
|
|
69
|
+
/** The incoming Request object */
|
|
70
|
+
request: Request;
|
|
71
|
+
/** URL parameters extracted from the route pattern */
|
|
72
|
+
params: Record<string, string>;
|
|
73
|
+
/** Parsed URL object */
|
|
74
|
+
url: URL;
|
|
75
|
+
/** Shared state for passing data between middlewares */
|
|
76
|
+
state: Map<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type NextFunction = () => Promise<Response>;
|
|
80
|
+
export type Middleware = (context: Context, next: NextFunction) => Response | Promise<Response>;
|
|
81
|
+
export type RouteHandler = (context: Context) => Response | Promise<Response>;
|
|
82
|
+
|
|
83
|
+
// ============================================================================
|
|
84
|
+
// Configuration
|
|
85
|
+
// ============================================================================
|
|
5
86
|
|
|
6
87
|
export interface RipplePluginOptions {
|
|
7
88
|
excludeRippleExternalModules?: boolean;
|
|
8
89
|
}
|
|
90
|
+
|
|
91
|
+
export interface RippleConfigOptions {
|
|
92
|
+
build?: {
|
|
93
|
+
minify?: boolean;
|
|
94
|
+
};
|
|
95
|
+
adapter?: {
|
|
96
|
+
serve: AdapterServeFunction;
|
|
97
|
+
};
|
|
98
|
+
router: {
|
|
99
|
+
routes: Route[];
|
|
100
|
+
};
|
|
101
|
+
/** Global middlewares applied to all routes */
|
|
102
|
+
middlewares?: Middleware[];
|
|
103
|
+
platform?: {
|
|
104
|
+
env: Record<string, string>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type AdapterServeFunction = (
|
|
109
|
+
handler: (request: Request, platform?: unknown) => Response | Promise<Response>,
|
|
110
|
+
options?: Record<string, unknown>,
|
|
111
|
+
) => { listen: (port?: number) => unknown; close: () => void };
|
|
9
112
|
}
|