@meridianjs/framework 0.1.5 → 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
@@ -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
@@ -724,8 +724,55 @@ function validate(schema) {
724
724
  next();
725
725
  };
726
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();
727
773
  export {
728
774
  ConsoleLogger,
775
+ SseManager,
729
776
  apiRateLimit,
730
777
  asClass,
731
778
  asFunction,
@@ -744,5 +791,6 @@ export {
744
791
  loadRoutes,
745
792
  loadSubscribers,
746
793
  resolveModuleDefinition,
794
+ sseManager,
747
795
  validate
748
796
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridianjs/framework",
3
- "version": "0.1.5",
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",