@jay-framework/stack-server-runtime 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.
- package/dist/index.d.ts +536 -4
- package/dist/index.js +993 -36
- package/package.json +11 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AnyJayStackComponentDefinition, PageProps, AnySlowlyRenderResult, UrlParams, JayStackComponentDefinition, AnyFastRenderResult, ServiceMarker } from '@jay-framework/fullstack-component';
|
|
1
|
+
import { AnyJayStackComponentDefinition, PageProps, AnySlowlyRenderResult, UrlParams, JayStackComponentDefinition, AnyFastRenderResult, HttpMethod, CacheOptions, JayAction, JayActionDefinition, ServiceMarker } from '@jay-framework/fullstack-component';
|
|
2
2
|
import { JayComponentCore } from '@jay-framework/component';
|
|
3
3
|
import { ViteDevServer } from 'vite';
|
|
4
4
|
import { JayRoute } from '@jay-framework/stack-route-scanner';
|
|
5
5
|
import { WithValidations } from '@jay-framework/compiler-shared';
|
|
6
6
|
import { JayRollupConfig } from '@jay-framework/rollup-plugin';
|
|
7
|
+
import { TrackByMap } from '@jay-framework/view-state-merge';
|
|
7
8
|
|
|
8
9
|
interface DevServerPagePart {
|
|
9
10
|
compDefinition: AnyJayStackComponentDefinition;
|
|
@@ -11,7 +12,24 @@ interface DevServerPagePart {
|
|
|
11
12
|
clientImport: string;
|
|
12
13
|
clientPart: string;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
interface LoadedPageParts {
|
|
16
|
+
parts: DevServerPagePart[];
|
|
17
|
+
/** TrackBy map for server-side merge (slow → fast) */
|
|
18
|
+
serverTrackByMap?: Record<string, string>;
|
|
19
|
+
/** TrackBy map for client-side merge (fast → interactive) */
|
|
20
|
+
clientTrackByMap?: Record<string, string>;
|
|
21
|
+
/** NPM package names used on this page (for filtering plugin inits) */
|
|
22
|
+
usedPackages: Set<string>;
|
|
23
|
+
}
|
|
24
|
+
interface LoadPagePartsOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Path to pre-rendered jay-html file to use instead of the original.
|
|
27
|
+
* When provided, this file (with slow-phase bindings resolved) is read.
|
|
28
|
+
* Import resolution still uses the original jay-html's directory.
|
|
29
|
+
*/
|
|
30
|
+
preRenderedPath?: string;
|
|
31
|
+
}
|
|
32
|
+
declare function loadPageParts(vite: ViteDevServer, route: JayRoute, pagesBase: string, projectBase: string, jayRollupConfig: JayRollupConfig, options?: LoadPagePartsOptions): Promise<WithValidations<LoadedPageParts>>;
|
|
15
33
|
|
|
16
34
|
interface SlowlyChangingPhase {
|
|
17
35
|
runSlowlyForPage(pageParams: object, pageProps: PageProps, parts: Array<DevServerPagePart>): Promise<AnySlowlyRenderResult>;
|
|
@@ -26,7 +44,395 @@ declare function runSlowlyChangingRender<Refs extends object, SlowVS extends obj
|
|
|
26
44
|
|
|
27
45
|
declare function renderFastChangingData(pageParams: object, pageProps: PageProps, carryForward: object, parts: Array<DevServerPagePart>): Promise<AnyFastRenderResult>;
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Action registry for Jay Stack server-side action handling.
|
|
49
|
+
*
|
|
50
|
+
* Actions are registered at build/startup time and can be invoked via HTTP.
|
|
51
|
+
* The registry maps action names to their definitions (handler, services, method, etc.).
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Registered action entry with resolved metadata.
|
|
56
|
+
*/
|
|
57
|
+
interface RegisteredAction {
|
|
58
|
+
/** Unique action name */
|
|
59
|
+
actionName: string;
|
|
60
|
+
/** HTTP method */
|
|
61
|
+
method: HttpMethod;
|
|
62
|
+
/** Cache options (for GET requests) */
|
|
63
|
+
cacheOptions?: CacheOptions;
|
|
64
|
+
/** Service markers for dependency injection */
|
|
65
|
+
services: any[];
|
|
66
|
+
/** The handler function */
|
|
67
|
+
handler: (input: any, ...services: any[]) => Promise<any>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Result of executing an action.
|
|
71
|
+
*/
|
|
72
|
+
type ActionExecutionResult<T> = {
|
|
73
|
+
success: true;
|
|
74
|
+
data: T;
|
|
75
|
+
} | {
|
|
76
|
+
success: false;
|
|
77
|
+
error: ActionErrorResponse;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Error response structure for failed actions.
|
|
81
|
+
*/
|
|
82
|
+
interface ActionErrorResponse {
|
|
83
|
+
code: string;
|
|
84
|
+
message: string;
|
|
85
|
+
isActionError: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Registry for Jay Stack server actions.
|
|
89
|
+
*
|
|
90
|
+
* Manages action registration, lookup, and execution.
|
|
91
|
+
* Create instances for testing or use the default export for production.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // For testing - create isolated instance
|
|
96
|
+
* const registry = new ActionRegistry();
|
|
97
|
+
* registry.register(myAction);
|
|
98
|
+
* const result = await registry.execute('my.action', input);
|
|
99
|
+
*
|
|
100
|
+
* // For production - use default instance
|
|
101
|
+
* import { actionRegistry } from '@jay-framework/stack-server-runtime';
|
|
102
|
+
* actionRegistry.register(myAction);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare class ActionRegistry {
|
|
106
|
+
private readonly actions;
|
|
107
|
+
/**
|
|
108
|
+
* Registers an action with the registry.
|
|
109
|
+
*
|
|
110
|
+
* @param action - The JayAction to register (created via makeJayAction/makeJayQuery)
|
|
111
|
+
*/
|
|
112
|
+
register<I, O, S extends any[]>(action: JayAction<I, O> & JayActionDefinition<I, O, S>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves a registered action by name.
|
|
115
|
+
*
|
|
116
|
+
* @param actionName - The unique action name
|
|
117
|
+
* @returns The registered action or undefined
|
|
118
|
+
*/
|
|
119
|
+
get(actionName: string): RegisteredAction | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Checks if an action is registered.
|
|
122
|
+
*
|
|
123
|
+
* @param actionName - The unique action name
|
|
124
|
+
* @returns true if the action is registered
|
|
125
|
+
*/
|
|
126
|
+
has(actionName: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Gets all registered action names.
|
|
129
|
+
*
|
|
130
|
+
* @returns Array of registered action names
|
|
131
|
+
*/
|
|
132
|
+
getNames(): string[];
|
|
133
|
+
/**
|
|
134
|
+
* Clears all registered actions.
|
|
135
|
+
*/
|
|
136
|
+
clear(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Executes a registered action with the given input.
|
|
139
|
+
* Resolves services and calls the handler.
|
|
140
|
+
*
|
|
141
|
+
* @param actionName - The action to execute
|
|
142
|
+
* @param input - The input data for the action
|
|
143
|
+
* @returns The action result or error
|
|
144
|
+
*/
|
|
145
|
+
execute<T = any>(actionName: string, input: unknown): Promise<ActionExecutionResult<T>>;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the cache headers for an action (if applicable).
|
|
148
|
+
*
|
|
149
|
+
* @param actionName - The action name
|
|
150
|
+
* @returns Cache-Control header value or undefined
|
|
151
|
+
*/
|
|
152
|
+
getCacheHeaders(actionName: string): string | undefined;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Default action registry instance.
|
|
156
|
+
* Use this for production; create new instances for testing.
|
|
157
|
+
*/
|
|
158
|
+
declare const actionRegistry: ActionRegistry;
|
|
159
|
+
/**
|
|
160
|
+
* Registers an action with the default registry.
|
|
161
|
+
* @deprecated Use actionRegistry.register() instead
|
|
162
|
+
*/
|
|
163
|
+
declare function registerAction<I, O, S extends any[]>(action: JayAction<I, O> & JayActionDefinition<I, O, S>): void;
|
|
164
|
+
/**
|
|
165
|
+
* Retrieves a registered action by name from the default registry.
|
|
166
|
+
* @deprecated Use actionRegistry.get() instead
|
|
167
|
+
*/
|
|
168
|
+
declare function getRegisteredAction(actionName: string): RegisteredAction | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Checks if an action is registered in the default registry.
|
|
171
|
+
* @deprecated Use actionRegistry.has() instead
|
|
172
|
+
*/
|
|
173
|
+
declare function hasAction(actionName: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Gets all registered action names from the default registry.
|
|
176
|
+
* @deprecated Use actionRegistry.getNames() instead
|
|
177
|
+
*/
|
|
178
|
+
declare function getRegisteredActionNames(): string[];
|
|
179
|
+
/**
|
|
180
|
+
* Clears all registered actions from the default registry.
|
|
181
|
+
* @deprecated Use actionRegistry.clear() instead
|
|
182
|
+
*/
|
|
183
|
+
declare function clearActionRegistry(): void;
|
|
184
|
+
/**
|
|
185
|
+
* Executes an action from the default registry.
|
|
186
|
+
* @deprecated Use actionRegistry.execute() instead
|
|
187
|
+
*/
|
|
188
|
+
declare function executeAction<T = any>(actionName: string, input: unknown): Promise<ActionExecutionResult<T>>;
|
|
189
|
+
/**
|
|
190
|
+
* Gets cache headers for an action from the default registry.
|
|
191
|
+
* @deprecated Use actionRegistry.getCacheHeaders() instead
|
|
192
|
+
*/
|
|
193
|
+
declare function getActionCacheHeaders(actionName: string): string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Executes an action directly with proper service injection.
|
|
196
|
+
* Use this when calling actions from backend code (e.g., render phases).
|
|
197
|
+
*
|
|
198
|
+
* Unlike calling the action directly (which bypasses service injection),
|
|
199
|
+
* this function resolves services and calls the handler correctly.
|
|
200
|
+
*
|
|
201
|
+
* @param action - The JayAction to execute (with definition metadata)
|
|
202
|
+
* @param input - The input data for the action
|
|
203
|
+
* @returns The action result (throws on error)
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // In a render phase
|
|
208
|
+
* import { runAction } from '@jay-framework/stack-server-runtime';
|
|
209
|
+
* import { searchProducts } from '../actions/stores-actions';
|
|
210
|
+
*
|
|
211
|
+
* async function renderFastChanging(props, slowCarryForward, wixStores) {
|
|
212
|
+
* // ✅ Correct - services are injected
|
|
213
|
+
* const result = await runAction(searchProducts, { query: '', pageSize: 12 });
|
|
214
|
+
*
|
|
215
|
+
* // ❌ Wrong - services are NOT injected (passes empty array)
|
|
216
|
+
* // const result = await searchProducts({ query: '', pageSize: 12 });
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function runAction<I, O>(action: JayAction<I, O> & JayActionDefinition<I, O, any[]>, input: I): Promise<O>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Action discovery and auto-registration for Jay Stack.
|
|
224
|
+
*
|
|
225
|
+
* Scans project and plugin directories to discover and register actions
|
|
226
|
+
* automatically on server startup.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Vite server interface for SSR module loading.
|
|
231
|
+
* Using a minimal interface to avoid direct Vite dependency.
|
|
232
|
+
*/
|
|
233
|
+
interface ViteSSRLoader {
|
|
234
|
+
ssrLoadModule: (url: string) => Promise<Record<string, any>>;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Options for action discovery.
|
|
238
|
+
*/
|
|
239
|
+
interface ActionDiscoveryOptions {
|
|
240
|
+
/** Project root directory */
|
|
241
|
+
projectRoot: string;
|
|
242
|
+
/** Custom actions directory (default: src/actions) */
|
|
243
|
+
actionsDir?: string;
|
|
244
|
+
/** Registry to register actions in (default: global actionRegistry) */
|
|
245
|
+
registry?: ActionRegistry;
|
|
246
|
+
/** Whether to log discovery progress */
|
|
247
|
+
verbose?: boolean;
|
|
248
|
+
/** Vite server for SSR module loading (required in dev for TypeScript files) */
|
|
249
|
+
viteServer?: ViteSSRLoader;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Result of action discovery.
|
|
253
|
+
*/
|
|
254
|
+
interface ActionDiscoveryResult {
|
|
255
|
+
/** Number of actions discovered and registered */
|
|
256
|
+
actionCount: number;
|
|
257
|
+
/** Names of registered actions */
|
|
258
|
+
actionNames: string[];
|
|
259
|
+
/** Paths of scanned action files */
|
|
260
|
+
scannedFiles: string[];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Discovers and registers actions from the project's actions directory.
|
|
264
|
+
*
|
|
265
|
+
* Scans `src/actions/*.actions.ts` for exported actions and registers them.
|
|
266
|
+
*
|
|
267
|
+
* @param options - Discovery options
|
|
268
|
+
* @returns Result with discovered action information
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* // In dev-server startup
|
|
273
|
+
* const result = await discoverAndRegisterActions({
|
|
274
|
+
* projectRoot: process.cwd(),
|
|
275
|
+
* verbose: true,
|
|
276
|
+
* });
|
|
277
|
+
* console.log(`Registered ${result.actionCount} actions`);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function discoverAndRegisterActions(options: ActionDiscoveryOptions): Promise<ActionDiscoveryResult>;
|
|
281
|
+
/**
|
|
282
|
+
* Options for discovering plugin actions.
|
|
283
|
+
*/
|
|
284
|
+
interface PluginActionDiscoveryOptions {
|
|
285
|
+
/** Project root directory */
|
|
286
|
+
projectRoot: string;
|
|
287
|
+
/** Registry to register actions in (default: global actionRegistry) */
|
|
288
|
+
registry?: ActionRegistry;
|
|
289
|
+
/** Whether to log discovery progress */
|
|
290
|
+
verbose?: boolean;
|
|
291
|
+
/** Vite server for SSR module loading (required in dev for TypeScript files) */
|
|
292
|
+
viteServer?: ViteSSRLoader;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Discovers and registers actions from all plugins in a project.
|
|
296
|
+
*
|
|
297
|
+
* Scans both local plugins (src/plugins/) and installed NPM plugins.
|
|
298
|
+
*
|
|
299
|
+
* @param options - Discovery options
|
|
300
|
+
* @returns Array of registered action names
|
|
301
|
+
*/
|
|
302
|
+
declare function discoverAllPluginActions(options: PluginActionDiscoveryOptions): Promise<string[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Discovers actions from a single plugin's plugin.yaml file.
|
|
305
|
+
*
|
|
306
|
+
* Reads plugin.yaml, finds the `actions` array, and imports those
|
|
307
|
+
* named exports from the plugin's module.
|
|
308
|
+
*
|
|
309
|
+
* @param pluginPath - Path to the plugin directory (containing plugin.yaml)
|
|
310
|
+
* @param projectRoot - Project root for resolving imports
|
|
311
|
+
* @param registry - Registry to register actions in
|
|
312
|
+
* @param verbose - Whether to log progress
|
|
313
|
+
* @returns Array of registered action names
|
|
314
|
+
*/
|
|
315
|
+
declare function discoverPluginActions(pluginPath: string, projectRoot: string, registry?: ActionRegistry, verbose?: boolean, viteServer?: ViteSSRLoader): Promise<string[]>;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Plugin initialization discovery and execution for Jay Stack.
|
|
319
|
+
*
|
|
320
|
+
* Discovers plugins with init configurations (using makeJayInit pattern),
|
|
321
|
+
* sorts them by dependencies, and executes their init functions in order.
|
|
322
|
+
*
|
|
323
|
+
* Auto-discovers `lib/init.ts` files in plugins, or uses the path specified
|
|
324
|
+
* in `plugin.yaml` via the `init` property.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Information about a discovered plugin with init.
|
|
329
|
+
*/
|
|
330
|
+
interface PluginWithInit {
|
|
331
|
+
/** Plugin name from plugin.yaml (used as default init key) */
|
|
332
|
+
name: string;
|
|
333
|
+
/** Plugin path (directory containing plugin.yaml) */
|
|
334
|
+
pluginPath: string;
|
|
335
|
+
/** Package name for NPM plugins, or path for local plugins */
|
|
336
|
+
packageName: string;
|
|
337
|
+
/** Whether this is a local plugin (src/plugins/) or NPM */
|
|
338
|
+
isLocal: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Init module path relative to plugin root.
|
|
341
|
+
* Default is 'lib/init' (auto-discovered).
|
|
342
|
+
* Can be overridden via `init` property in plugin.yaml.
|
|
343
|
+
*/
|
|
344
|
+
initModule: string;
|
|
345
|
+
/**
|
|
346
|
+
* Export name for the init constant.
|
|
347
|
+
* Default is 'init'.
|
|
348
|
+
* Can be overridden via `init` property in plugin.yaml (for compiled packages).
|
|
349
|
+
*/
|
|
350
|
+
initExport: string;
|
|
351
|
+
/** Dependencies from package.json (for ordering) */
|
|
352
|
+
dependencies: string[];
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Options for plugin init discovery.
|
|
356
|
+
*/
|
|
357
|
+
interface PluginInitDiscoveryOptions {
|
|
358
|
+
/** Project root directory */
|
|
359
|
+
projectRoot: string;
|
|
360
|
+
/** Whether to log discovery progress */
|
|
361
|
+
verbose?: boolean;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Discovers all plugins with init configurations.
|
|
365
|
+
*
|
|
366
|
+
* Auto-discovers `lib/init.ts` files in plugins, or uses the path specified
|
|
367
|
+
* in `plugin.yaml` via the `init` property.
|
|
368
|
+
*
|
|
369
|
+
* Scans both local plugins (src/plugins/) and NPM plugins (node_modules/).
|
|
370
|
+
* Also discovers transitive plugin dependencies (plugins that depend on other plugins).
|
|
371
|
+
*/
|
|
372
|
+
declare function discoverPluginsWithInit(options: PluginInitDiscoveryOptions): Promise<PluginWithInit[]>;
|
|
373
|
+
/**
|
|
374
|
+
* Sorts plugins by their dependencies (topological sort).
|
|
375
|
+
* Plugins with no dependencies come first, then plugins that depend on them, etc.
|
|
376
|
+
*/
|
|
377
|
+
declare function sortPluginsByDependencies(plugins: PluginWithInit[]): PluginWithInit[];
|
|
378
|
+
/**
|
|
379
|
+
* Executes server init for all plugins in order.
|
|
380
|
+
*
|
|
381
|
+
* Uses the `makeJayInit` pattern:
|
|
382
|
+
* - Loads the init module and finds the JayInit object
|
|
383
|
+
* - Calls `_serverInit()` if defined
|
|
384
|
+
* - Stores returned data via `setClientInitData(pluginName, data)`
|
|
385
|
+
*
|
|
386
|
+
* @param plugins - Sorted list of plugins with init
|
|
387
|
+
* @param viteServer - Vite server for SSR module loading (optional)
|
|
388
|
+
* @param verbose - Whether to log progress
|
|
389
|
+
*/
|
|
390
|
+
declare function executePluginServerInits(plugins: PluginWithInit[], viteServer?: ViteSSRLoader, verbose?: boolean): Promise<void>;
|
|
391
|
+
/**
|
|
392
|
+
* Information needed to generate client init script for a plugin.
|
|
393
|
+
*/
|
|
394
|
+
interface PluginClientInitInfo {
|
|
395
|
+
/** Plugin name (used for logging and as data key) */
|
|
396
|
+
name: string;
|
|
397
|
+
/** Import path for the init module */
|
|
398
|
+
importPath: string;
|
|
399
|
+
/** Export name for the JayInit constant */
|
|
400
|
+
initExport: string;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Prepares plugin information for client init script generation.
|
|
404
|
+
*
|
|
405
|
+
* For LOCAL plugins: Use the init file path directly
|
|
406
|
+
* For NPM plugins: Use the `/client` subpath (client bundle exports init)
|
|
407
|
+
*
|
|
408
|
+
* Filters to only plugins that have init modules and returns the
|
|
409
|
+
* information needed to generate client-side imports and execution.
|
|
410
|
+
*/
|
|
411
|
+
declare function preparePluginClientInits(plugins: PluginWithInit[]): PluginClientInitInfo[];
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Information needed to generate client init script for the project.
|
|
415
|
+
*/
|
|
416
|
+
interface ProjectClientInitInfo {
|
|
417
|
+
/** Import path for the init module */
|
|
418
|
+
importPath: string;
|
|
419
|
+
/** Export name for the JayInit constant (default: 'init') */
|
|
420
|
+
initExport?: string;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Options for client script generation.
|
|
424
|
+
*/
|
|
425
|
+
interface GenerateClientScriptOptions {
|
|
426
|
+
/** Enable automation integration (default: true in dev mode) */
|
|
427
|
+
enableAutomation?: boolean;
|
|
428
|
+
/**
|
|
429
|
+
* Slow ViewState that was baked into the pre-rendered jay-html.
|
|
430
|
+
* When provided, this is merged with fastViewState for the automation API
|
|
431
|
+
* so that AI/automation tools can see the complete page state.
|
|
432
|
+
*/
|
|
433
|
+
slowViewState?: object;
|
|
434
|
+
}
|
|
435
|
+
declare function generateClientScript(defaultViewState: object, fastCarryForward: object, parts: DevServerPagePart[], jayHtmlPath: string, trackByMap?: TrackByMap, clientInitData?: Record<string, Record<string, any>>, projectInit?: ProjectClientInitInfo, pluginInits?: PluginClientInitInfo[], options?: GenerateClientScriptOptions): string;
|
|
30
436
|
|
|
31
437
|
/**
|
|
32
438
|
* Service registry for Jay Stack server-side dependency injection.
|
|
@@ -144,5 +550,131 @@ declare function runShutdownCallbacks(): Promise<void>;
|
|
|
144
550
|
* Internal API used by dev-server during hot reload.
|
|
145
551
|
*/
|
|
146
552
|
declare function clearLifecycleCallbacks(): void;
|
|
553
|
+
/**
|
|
554
|
+
* Sets client init data for a specific namespace (plugin or project).
|
|
555
|
+
* Each namespace's data is kept separate and passed only to the matching
|
|
556
|
+
* client init callback.
|
|
557
|
+
*
|
|
558
|
+
* @param key - Namespace key (plugin name or 'project')
|
|
559
|
+
* @param data - Data object for this namespace
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* // In plugin server init
|
|
564
|
+
* onInit(async () => {
|
|
565
|
+
* setClientInitData('wix-stores', {
|
|
566
|
+
* currency: 'USD',
|
|
567
|
+
* apiEndpoint: process.env.STORES_API_URL,
|
|
568
|
+
* });
|
|
569
|
+
* });
|
|
570
|
+
*
|
|
571
|
+
* // In project jay.init.ts
|
|
572
|
+
* onInit(async () => {
|
|
573
|
+
* setClientInitData('project', {
|
|
574
|
+
* oauthClientId: process.env.OAUTH_CLIENT_ID,
|
|
575
|
+
* featureFlags: await loadFeatureFlags(),
|
|
576
|
+
* });
|
|
577
|
+
* });
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
declare function setClientInitData(key: string, data: Record<string, any>): void;
|
|
581
|
+
/**
|
|
582
|
+
* Gets all namespaced client init data.
|
|
583
|
+
* Internal API used by page rendering to embed data in HTML.
|
|
584
|
+
*
|
|
585
|
+
* @returns Object with namespace keys and their data
|
|
586
|
+
*/
|
|
587
|
+
declare function getClientInitData(): Record<string, Record<string, any>>;
|
|
588
|
+
/**
|
|
589
|
+
* Gets client init data for a specific namespace.
|
|
590
|
+
*
|
|
591
|
+
* @param key - Namespace key
|
|
592
|
+
* @returns Data for that namespace, or empty object if not set
|
|
593
|
+
*/
|
|
594
|
+
declare function getClientInitDataForKey(key: string): Record<string, any>;
|
|
595
|
+
/**
|
|
596
|
+
* Clears client init data.
|
|
597
|
+
* Internal API used by dev-server during hot reload.
|
|
598
|
+
*/
|
|
599
|
+
declare function clearClientInitData(): void;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Cache entry for pre-rendered jay-html
|
|
603
|
+
*/
|
|
604
|
+
interface SlowRenderCacheEntry {
|
|
605
|
+
/** Path to the pre-rendered jay-html file on disk */
|
|
606
|
+
preRenderedPath: string;
|
|
607
|
+
/** Slow ViewState that was baked into the jay-html */
|
|
608
|
+
slowViewState: object;
|
|
609
|
+
/** CarryForward data from slow rendering (passed to fast phase) */
|
|
610
|
+
carryForward: object;
|
|
611
|
+
/** Timestamp when this entry was created */
|
|
612
|
+
createdAt: number;
|
|
613
|
+
/** Source jay-html path (for debugging) */
|
|
614
|
+
sourcePath: string;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Cache for pre-rendered jay-html files.
|
|
618
|
+
*
|
|
619
|
+
* This cache stores jay-html content that has been transformed with slow-phase
|
|
620
|
+
* data baked in. The key insight is that since slow ViewState is embedded directly
|
|
621
|
+
* into the jay-html, we don't need to pass it to the client - only fast and
|
|
622
|
+
* interactive ViewState is sent.
|
|
623
|
+
*
|
|
624
|
+
* Pre-rendered files are written to disk so Vite can pick them up and compile them.
|
|
625
|
+
*/
|
|
626
|
+
declare class SlowRenderCache {
|
|
627
|
+
private cache;
|
|
628
|
+
private pathToKeys;
|
|
629
|
+
private readonly cacheDir;
|
|
630
|
+
private readonly pagesRoot;
|
|
631
|
+
/**
|
|
632
|
+
* @param cacheDir - Directory where pre-rendered jay-html files are stored
|
|
633
|
+
* @param pagesRoot - Root directory of the pages (for relative path calculation)
|
|
634
|
+
*/
|
|
635
|
+
constructor(cacheDir: string, pagesRoot: string);
|
|
636
|
+
/**
|
|
637
|
+
* Get a cached pre-rendered jay-html entry
|
|
638
|
+
*/
|
|
639
|
+
get(jayHtmlPath: string, params: Record<string, string>): SlowRenderCacheEntry | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Store a pre-rendered jay-html entry in the cache.
|
|
642
|
+
* Writes the pre-rendered content to disk and stores metadata in memory.
|
|
643
|
+
*/
|
|
644
|
+
set(jayHtmlPath: string, params: Record<string, string>, preRenderedJayHtml: string, slowViewState: object, carryForward: object): Promise<string>;
|
|
645
|
+
/**
|
|
646
|
+
* Check if a pre-rendered entry exists for the given path and params
|
|
647
|
+
*/
|
|
648
|
+
has(jayHtmlPath: string, params: Record<string, string>): boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Invalidate all cached entries for a given jay-html source path.
|
|
651
|
+
* This is called when the source file changes.
|
|
652
|
+
* Also deletes the cached files from disk.
|
|
653
|
+
*/
|
|
654
|
+
invalidate(jayHtmlPath: string): Promise<void>;
|
|
655
|
+
/**
|
|
656
|
+
* Invalidate all entries that depend on a changed file.
|
|
657
|
+
* The changedPath could be:
|
|
658
|
+
* - A jay-html file itself
|
|
659
|
+
* - A component file (page.ts)
|
|
660
|
+
* - Any other dependency
|
|
661
|
+
*
|
|
662
|
+
* @param changedPath - Absolute path to the changed file
|
|
663
|
+
* @param resolveDependencies - Optional function to resolve which jay-html files depend on the changed file
|
|
664
|
+
*/
|
|
665
|
+
invalidateByDependency(changedPath: string, resolveDependencies?: (changedPath: string) => string[]): Promise<void>;
|
|
666
|
+
/**
|
|
667
|
+
* Clear all cached entries and delete cached files from disk
|
|
668
|
+
*/
|
|
669
|
+
clear(): Promise<void>;
|
|
670
|
+
/**
|
|
671
|
+
* Get the number of cached entries
|
|
672
|
+
*/
|
|
673
|
+
get size(): number;
|
|
674
|
+
/**
|
|
675
|
+
* Get all cached jay-html paths (for debugging/monitoring)
|
|
676
|
+
*/
|
|
677
|
+
getCachedPaths(): string[];
|
|
678
|
+
}
|
|
147
679
|
|
|
148
|
-
export { DevSlowlyChangingPhase, type SlowlyChangingPhase, clearLifecycleCallbacks, clearServiceRegistry, generateClientScript, getService, hasService, loadPageParts, onInit, onShutdown, registerService, renderFastChangingData, resolveServices, runInitCallbacks, runLoadParams, runShutdownCallbacks, runSlowlyChangingRender };
|
|
680
|
+
export { type ActionDiscoveryOptions, type ActionDiscoveryResult, type ActionErrorResponse, type ActionExecutionResult, ActionRegistry, type DevServerPagePart, DevSlowlyChangingPhase, type GenerateClientScriptOptions, type LoadedPageParts, type PluginActionDiscoveryOptions, type PluginClientInitInfo, type PluginInitDiscoveryOptions, type PluginWithInit, type ProjectClientInitInfo, type RegisteredAction, SlowRenderCache, type SlowRenderCacheEntry, type SlowlyChangingPhase, type ViteSSRLoader, actionRegistry, clearActionRegistry, clearClientInitData, clearLifecycleCallbacks, clearServiceRegistry, discoverAllPluginActions, discoverAndRegisterActions, discoverPluginActions, discoverPluginsWithInit, executeAction, executePluginServerInits, generateClientScript, getActionCacheHeaders, getClientInitData, getClientInitDataForKey, getRegisteredAction, getRegisteredActionNames, getService, hasAction, hasService, loadPageParts, onInit, onShutdown, preparePluginClientInits, registerAction, registerService, renderFastChangingData, resolveServices, runAction, runInitCallbacks, runLoadParams, runShutdownCallbacks, runSlowlyChangingRender, setClientInitData, sortPluginsByDependencies };
|