@jay-framework/dev-server 0.8.0 → 0.10.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +79 -9
  2. package/dist/index.js +1585 -57
  3. package/package.json +13 -12
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import { ViteDevServer, Connect } from 'vite';
2
2
  import { JayRoute } from '@jay-framework/stack-route-scanner';
3
3
  import { RequestHandler } from 'express-serve-static-core';
4
4
  import { JayRollupConfig } from '@jay-framework/rollup-plugin';
5
+ import { ProjectClientInitInfo, PluginWithInit, ActionRegistry } from '@jay-framework/stack-server-runtime';
6
+ import { RequestHandler as RequestHandler$1 } from 'express';
5
7
 
6
8
  interface DevServerOptions {
7
9
  publicBaseUrlPath?: string;
@@ -14,30 +16,40 @@ interface DevServerOptions {
14
16
  /**
15
17
  * Service lifecycle management for the Jay Stack dev-server.
16
18
  *
17
- * Handles loading jay.init.ts, running init/shutdown callbacks,
18
- * hot reloading services, and graceful shutdown.
19
+ * Handles loading lib/init.ts, running init/shutdown callbacks,
20
+ * hot reloading services, graceful shutdown, and action auto-discovery.
19
21
  */
20
22
 
21
23
  declare class ServiceLifecycleManager {
22
24
  private projectRoot;
23
25
  private sourceBase;
24
- private initFilePath;
26
+ /** Path to project's lib/init.ts (makeJayInit pattern) */
27
+ private projectInitFilePath;
25
28
  private isInitialized;
26
29
  private viteServer;
30
+ private pluginsWithInit;
27
31
  constructor(projectRoot: string, sourceBase?: string);
28
32
  /**
29
33
  * Set the Vite server instance for SSR module loading
30
34
  */
31
35
  setViteServer(viteServer: ViteDevServer): void;
32
36
  /**
33
- * Finds the jay.init.ts (or .js) file in the source directory.
34
- * Looks in: {projectRoot}/{sourceBase}/jay.init.{ts,js,mts,mjs}
37
+ * Finds the project init file using makeJayInit pattern.
38
+ * Looks in: {projectRoot}/{sourceBase}/init.{ts,js}
35
39
  */
36
- private findInitFile;
40
+ private findProjectInitFile;
37
41
  /**
38
- * Initializes services by loading and executing jay.init.ts
42
+ * Initializes services by:
43
+ * 1. Discovering and executing plugin server inits (in dependency order)
44
+ * 2. Loading and executing project lib/init.ts
45
+ * 3. Running all registered onInit callbacks
46
+ * 4. Auto-discovering and registering actions
39
47
  */
40
48
  initialize(): Promise<void>;
49
+ /**
50
+ * Auto-discovers and registers actions from project and plugins.
51
+ */
52
+ private discoverActions;
41
53
  /**
42
54
  * Shuts down services gracefully with timeout
43
55
  */
@@ -47,9 +59,18 @@ declare class ServiceLifecycleManager {
47
59
  */
48
60
  reload(): Promise<void>;
49
61
  /**
50
- * Returns the path to the init file if found
62
+ * Returns the path to the init file if found.
51
63
  */
52
64
  getInitFilePath(): string | null;
65
+ /**
66
+ * Returns project init info for client-side embedding.
67
+ */
68
+ getProjectInit(): ProjectClientInitInfo | null;
69
+ /**
70
+ * Returns the discovered plugins with init configurations.
71
+ * Sorted by dependencies (plugins with no deps first).
72
+ */
73
+ getPluginsWithInit(): PluginWithInit[];
53
74
  /**
54
75
  * Checks if services are initialized
55
76
  */
@@ -69,4 +90,53 @@ interface DevServer {
69
90
  }
70
91
  declare function mkDevServer(options: DevServerOptions): Promise<DevServer>;
71
92
 
72
- export { type DevServer, type DevServerOptions, type DevServerRoute, mkDevServer };
93
+ /**
94
+ * Action Router for Jay Stack dev server.
95
+ *
96
+ * Handles HTTP requests to /_jay/actions/:actionName
97
+ * and routes them to registered action handlers.
98
+ */
99
+
100
+ /**
101
+ * The base path for action endpoints.
102
+ */
103
+ declare const ACTION_ENDPOINT_BASE = "/_jay/actions";
104
+ /**
105
+ * Options for creating the action router.
106
+ */
107
+ interface ActionRouterOptions {
108
+ /**
109
+ * The action registry to use.
110
+ * Defaults to the global actionRegistry.
111
+ */
112
+ registry?: ActionRegistry;
113
+ }
114
+ /**
115
+ * Creates the action router middleware.
116
+ *
117
+ * Handles requests to /_jay/actions/:actionName
118
+ *
119
+ * For GET requests, input is parsed from query string.
120
+ * For POST/PUT/PATCH/DELETE, input is parsed from request body.
121
+ *
122
+ * @param options - Optional configuration including custom registry for testing
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // In dev-server setup (uses default registry)
127
+ * const actionRouter = createActionRouter();
128
+ * app.use(ACTION_ENDPOINT_BASE, actionRouter);
129
+ *
130
+ * // For testing (uses isolated registry)
131
+ * const testRegistry = new ActionRegistry();
132
+ * const actionRouter = createActionRouter({ registry: testRegistry });
133
+ * ```
134
+ */
135
+ declare function createActionRouter(options?: ActionRouterOptions): RequestHandler$1;
136
+ /**
137
+ * Express middleware to parse JSON body for action requests.
138
+ * Should be applied before the action router.
139
+ */
140
+ declare function actionBodyParser(): RequestHandler$1;
141
+
142
+ export { ACTION_ENDPOINT_BASE, type ActionRouterOptions, type DevServer, type DevServerOptions, type DevServerRoute, actionBodyParser, createActionRouter, mkDevServer };