@jay-framework/dev-server 0.9.0 → 0.11.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 +91 -9
  2. package/dist/index.js +1212 -134
  3. package/package.json +13 -12
package/dist/index.d.ts CHANGED
@@ -2,42 +2,66 @@ 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;
8
10
  projectRootFolder?: string;
9
11
  pagesRootFolder?: string;
12
+ /**
13
+ * Folder where build artifacts are stored.
14
+ * Pre-rendered jay-html files are written to `<buildFolder>/slow-render-cache/`.
15
+ * Defaults to `<projectRootFolder>/build`.
16
+ */
17
+ buildFolder?: string;
10
18
  jayRollupConfig: JayRollupConfig;
11
19
  dontCacheSlowly: boolean;
20
+ /**
21
+ * Disable automation integration.
22
+ * When false (default), pages are wrapped with automation API for dev tooling.
23
+ * The automation API is available at `window.__jay.automation` and via `AUTOMATION_CONTEXT`.
24
+ */
25
+ disableAutomation?: boolean;
12
26
  }
13
27
 
14
28
  /**
15
29
  * Service lifecycle management for the Jay Stack dev-server.
16
30
  *
17
- * Handles loading jay.init.ts, running init/shutdown callbacks,
18
- * hot reloading services, and graceful shutdown.
31
+ * Handles loading lib/init.ts, running init/shutdown callbacks,
32
+ * hot reloading services, graceful shutdown, and action auto-discovery.
19
33
  */
20
34
 
21
35
  declare class ServiceLifecycleManager {
22
36
  private projectRoot;
23
37
  private sourceBase;
24
- private initFilePath;
38
+ /** Path to project's lib/init.ts (makeJayInit pattern) */
39
+ private projectInitFilePath;
25
40
  private isInitialized;
26
41
  private viteServer;
42
+ private pluginsWithInit;
27
43
  constructor(projectRoot: string, sourceBase?: string);
28
44
  /**
29
45
  * Set the Vite server instance for SSR module loading
30
46
  */
31
47
  setViteServer(viteServer: ViteDevServer): void;
32
48
  /**
33
- * Finds the jay.init.ts (or .js) file in the source directory.
34
- * Looks in: {projectRoot}/{sourceBase}/jay.init.{ts,js,mts,mjs}
49
+ * Finds the project init file using makeJayInit pattern.
50
+ * Looks in: {projectRoot}/{sourceBase}/init.{ts,js}
35
51
  */
36
- private findInitFile;
52
+ private findProjectInitFile;
37
53
  /**
38
- * Initializes services by loading and executing jay.init.ts
54
+ * Initializes services by:
55
+ * 1. Discovering and executing plugin server inits (in dependency order)
56
+ * 2. Loading and executing project lib/init.ts
57
+ * 3. Running all registered onInit callbacks
58
+ * 4. Auto-discovering and registering actions
39
59
  */
40
60
  initialize(): Promise<void>;
61
+ /**
62
+ * Auto-discovers and registers actions from project and plugins.
63
+ */
64
+ private discoverActions;
41
65
  /**
42
66
  * Shuts down services gracefully with timeout
43
67
  */
@@ -47,9 +71,18 @@ declare class ServiceLifecycleManager {
47
71
  */
48
72
  reload(): Promise<void>;
49
73
  /**
50
- * Returns the path to the init file if found
74
+ * Returns the path to the init file if found.
51
75
  */
52
76
  getInitFilePath(): string | null;
77
+ /**
78
+ * Returns project init info for client-side embedding.
79
+ */
80
+ getProjectInit(): ProjectClientInitInfo | null;
81
+ /**
82
+ * Returns the discovered plugins with init configurations.
83
+ * Sorted by dependencies (plugins with no deps first).
84
+ */
85
+ getPluginsWithInit(): PluginWithInit[];
53
86
  /**
54
87
  * Checks if services are initialized
55
88
  */
@@ -69,4 +102,53 @@ interface DevServer {
69
102
  }
70
103
  declare function mkDevServer(options: DevServerOptions): Promise<DevServer>;
71
104
 
72
- export { type DevServer, type DevServerOptions, type DevServerRoute, mkDevServer };
105
+ /**
106
+ * Action Router for Jay Stack dev server.
107
+ *
108
+ * Handles HTTP requests to /_jay/actions/:actionName
109
+ * and routes them to registered action handlers.
110
+ */
111
+
112
+ /**
113
+ * The base path for action endpoints.
114
+ */
115
+ declare const ACTION_ENDPOINT_BASE = "/_jay/actions";
116
+ /**
117
+ * Options for creating the action router.
118
+ */
119
+ interface ActionRouterOptions {
120
+ /**
121
+ * The action registry to use.
122
+ * Defaults to the global actionRegistry.
123
+ */
124
+ registry?: ActionRegistry;
125
+ }
126
+ /**
127
+ * Creates the action router middleware.
128
+ *
129
+ * Handles requests to /_jay/actions/:actionName
130
+ *
131
+ * For GET requests, input is parsed from query string.
132
+ * For POST/PUT/PATCH/DELETE, input is parsed from request body.
133
+ *
134
+ * @param options - Optional configuration including custom registry for testing
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // In dev-server setup (uses default registry)
139
+ * const actionRouter = createActionRouter();
140
+ * app.use(ACTION_ENDPOINT_BASE, actionRouter);
141
+ *
142
+ * // For testing (uses isolated registry)
143
+ * const testRegistry = new ActionRegistry();
144
+ * const actionRouter = createActionRouter({ registry: testRegistry });
145
+ * ```
146
+ */
147
+ declare function createActionRouter(options?: ActionRouterOptions): RequestHandler$1;
148
+ /**
149
+ * Express middleware to parse JSON body for action requests.
150
+ * Should be applied before the action router.
151
+ */
152
+ declare function actionBodyParser(): RequestHandler$1;
153
+
154
+ export { ACTION_ENDPOINT_BASE, type ActionRouterOptions, type DevServer, type DevServerOptions, type DevServerRoute, actionBodyParser, createActionRouter, mkDevServer };