@meridianjs/framework 0.1.4 → 0.1.6

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 CHANGED
@@ -159,7 +159,7 @@ declare function loadLinks(container: MeridianContainer, linksDir: string): Prom
159
159
  * - relative local path: "./src/plugins/my-plugin"
160
160
  * - absolute path: "/absolute/path/to/plugin"
161
161
  */
162
- declare function loadPlugins(container: MeridianContainer, plugins: PluginConfig[], rootDir: string): Promise<void>;
162
+ declare function loadPlugins(container: MeridianContainer, plugins: PluginConfig[], rootDir: string, server?: any): Promise<void>;
163
163
 
164
164
  declare class ConsoleLogger implements ILogger {
165
165
  private readonly prefix;
@@ -191,4 +191,24 @@ declare const apiRateLimit: express_rate_limit.RateLimitRequestHandler;
191
191
  */
192
192
  declare function validate(schema: ZodSchema): (req: Request, res: Response, next: NextFunction) => void;
193
193
 
194
- export { type BootstrapOptions, ConsoleLogger, type MeridianApp, type MiddlewareRoute, type MiddlewaresConfig, apiRateLimit, authRateLimit, bootstrap, createMeridianContainer, createServer, defineConfig, defineMiddlewares, loadConfig, loadJobs, loadLinks, loadModules, loadPlugins, loadRoutes, loadSubscribers, resolveModuleDefinition, validate };
194
+ /**
195
+ * Manages Server-Sent Event (SSE) connections grouped by workspace.
196
+ * Subscribers call broadcast() after mutations; the frontend receives live updates
197
+ * and invalidates the relevant TanStack Query cache entries.
198
+ */
199
+ declare class SseManager {
200
+ private clients;
201
+ /**
202
+ * Registers a response as an SSE client for the given workspace.
203
+ * Returns an unsubscribe function to call on connection close.
204
+ */
205
+ subscribe(workspaceId: string, res: Response): () => void;
206
+ /**
207
+ * Sends an SSE event to all connected clients in the given workspace.
208
+ */
209
+ broadcast(workspaceId: string, event: string, data: unknown): void;
210
+ }
211
+ /** Singleton shared across all routes and subscribers. */
212
+ declare const sseManager: SseManager;
213
+
214
+ export { type BootstrapOptions, ConsoleLogger, type MeridianApp, type MiddlewareRoute, type MiddlewaresConfig, SseManager, apiRateLimit, authRateLimit, bootstrap, createMeridianContainer, createServer, defineConfig, defineMiddlewares, loadConfig, loadJobs, loadLinks, loadModules, loadPlugins, loadRoutes, loadSubscribers, resolveModuleDefinition, sseManager, validate };
package/dist/index.js CHANGED
@@ -401,7 +401,7 @@ var QueryService = class {
401
401
  };
402
402
 
403
403
  // src/plugin-loader.ts
404
- async function loadPlugins(container, plugins, rootDir) {
404
+ async function loadPlugins(container, plugins, rootDir, server) {
405
405
  const logger = container.resolve("logger");
406
406
  for (const plugin of plugins) {
407
407
  logger.info(`Loading plugin: ${plugin.resolve}`);
@@ -444,17 +444,12 @@ async function loadPlugins(container, plugins, rootDir) {
444
444
  }
445
445
  }
446
446
  if (scanRoot) {
447
- await autoScanPlugin(scanRoot, container, logger);
447
+ await autoScanPlugin(scanRoot, container, logger, server);
448
448
  }
449
449
  logger.info(`Plugin loaded: ${plugin.resolve}`);
450
450
  }
451
451
  }
452
- async function autoScanPlugin(scanRoot, container, logger) {
453
- let server = null;
454
- try {
455
- server = container.resolve("server");
456
- } catch {
457
- }
452
+ async function autoScanPlugin(scanRoot, container, logger, server) {
458
453
  const candidates = [
459
454
  scanRoot,
460
455
  // pluginRoot already points to compiled dir
@@ -629,7 +624,7 @@ async function bootstrap(opts) {
629
624
  const server = createServer(container, config);
630
625
  container.register({ server });
631
626
  await loadMiddlewares(server, container, path8.join(rootDir, "src", "api"));
632
- await loadPlugins(container, config.plugins ?? [], rootDir);
627
+ await loadPlugins(container, config.plugins ?? [], rootDir, server);
633
628
  await loadLinks(container, path8.join(rootDir, "src", "links"));
634
629
  await loadRoutes(server, container, path8.join(rootDir, "src", "api"));
635
630
  await loadSubscribers(container, path8.join(rootDir, "src", "subscribers"));
@@ -729,8 +724,55 @@ function validate(schema) {
729
724
  next();
730
725
  };
731
726
  }
727
+
728
+ // src/sse-manager.ts
729
+ var SseManager = class {
730
+ clients = /* @__PURE__ */ new Map();
731
+ /**
732
+ * Registers a response as an SSE client for the given workspace.
733
+ * Returns an unsubscribe function to call on connection close.
734
+ */
735
+ subscribe(workspaceId, res) {
736
+ if (!this.clients.has(workspaceId)) {
737
+ this.clients.set(workspaceId, /* @__PURE__ */ new Set());
738
+ }
739
+ this.clients.get(workspaceId).add(res);
740
+ return () => {
741
+ const set = this.clients.get(workspaceId);
742
+ if (set) {
743
+ set.delete(res);
744
+ if (set.size === 0) this.clients.delete(workspaceId);
745
+ }
746
+ };
747
+ }
748
+ /**
749
+ * Sends an SSE event to all connected clients in the given workspace.
750
+ */
751
+ broadcast(workspaceId, event, data) {
752
+ const set = this.clients.get(workspaceId);
753
+ if (!set?.size) return;
754
+ const payload = `event: ${event}
755
+ data: ${JSON.stringify(data)}
756
+
757
+ `;
758
+ const dead = [];
759
+ for (const res of set) {
760
+ try {
761
+ res.write(payload);
762
+ } catch {
763
+ dead.push(res);
764
+ }
765
+ }
766
+ for (const res of dead) {
767
+ set.delete(res);
768
+ }
769
+ if (set.size === 0) this.clients.delete(workspaceId);
770
+ }
771
+ };
772
+ var sseManager = new SseManager();
732
773
  export {
733
774
  ConsoleLogger,
775
+ SseManager,
734
776
  apiRateLimit,
735
777
  asClass,
736
778
  asFunction,
@@ -749,5 +791,6 @@ export {
749
791
  loadRoutes,
750
792
  loadSubscribers,
751
793
  resolveModuleDefinition,
794
+ sseManager,
752
795
  validate
753
796
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridianjs/framework",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Core Meridian framework: bootstrap, DI container, module/route/subscriber/job loaders",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",