@iadev93/zuno-express 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -26,7 +26,9 @@ import { createZunoExpress } from "@iadev93/zuno-express";
26
26
  const app = express();
27
27
  app.use(express.json());
28
28
 
29
- const zuno = createZunoExpress();
29
+ const zuno = createZunoExpress({
30
+ batchSync: true // Optional: Enable batching
31
+ });
30
32
 
31
33
  // Unified handlers
32
34
  app.get("/zuno/sse", zuno.sse);
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
+ import { IncomingHttpHeaders } from 'node:http';
1
2
  import { Request, Response } from 'express';
2
- import { IncomingHttpHeaders } from 'http';
3
3
 
4
4
  /**
5
5
  * Options for creating an Express router for Zuno.
@@ -10,31 +10,67 @@ type CreateZunoExpressOptions = {
10
10
  };
11
11
  /**
12
12
  * Creates a Zuno Express instance.
13
- * @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.
14
- * @returns {Object} An object with the following properties:
15
- * - sse: An Express handler function that handles SSE connections.
16
- * - sync: An Express handler function that handles sync POST requests.
17
- * - snapshot: An Express handler function that handles snapshot GET requests.
13
+ * Returns both granular handlers and a convenience `mount` helper.
18
14
  */
19
15
  declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
20
16
  /**
21
- * Handles SSE connections for Express.
22
- * @param {Request} req - Express request object.
23
- * @param {Response} res - Express response object.
17
+ * Optional convenience method to mount all Zuno handlers at once.
18
+ * @param app The Express App or Router to mount the handlers on.
19
+ * @param basePath The base path for the Zuno routes (defaults to "/zuno").
20
+ */
21
+ mount: (app: {
22
+ get: Function;
23
+ post: Function;
24
+ }, basePath?: string) => void;
25
+ /**
26
+ * SSE connection handler.
27
+ * Usage: app.get('/custom/sse', zuno.sse);
28
+ */
29
+ sse: (req: Request, res: Response) => void;
30
+ /**
31
+ * Sync POST handler.
32
+ * Usage: app.post('/custom/sync', zuno.sync);
33
+ */
34
+ sync: (req: Request, res: Response) => void;
35
+ /**
36
+ * Snapshot GET handler.
37
+ * Usage: app.get('/custom/snapshot', zuno.snapshot);
38
+ */
39
+ snapshot: (req: Request, res: Response) => void;
40
+ };
41
+ /**
42
+ * A standalone helper to mount Zuno handlers on an Express app/router.
43
+ */
44
+ declare function mountZuno(app: {
45
+ get: Function;
46
+ post: Function;
47
+ }, opts?: CreateZunoExpressOptions & {
48
+ basePath?: string;
49
+ }): {
50
+ /**
51
+ * Optional convenience method to mount all Zuno handlers at once.
52
+ * @param app The Express App or Router to mount the handlers on.
53
+ * @param basePath The base path for the Zuno routes (defaults to "/zuno").
54
+ */
55
+ mount: (app: {
56
+ get: Function;
57
+ post: Function;
58
+ }, basePath?: string) => void;
59
+ /**
60
+ * SSE connection handler.
61
+ * Usage: app.get('/custom/sse', zuno.sse);
24
62
  */
25
63
  sse: (req: Request, res: Response) => void;
26
64
  /**
27
- * Handles sync POST requests for Express.
28
- * @param {Request} req - Express request object.
29
- * @param {Response} res - Express response object.
65
+ * Sync POST handler.
66
+ * Usage: app.post('/custom/sync', zuno.sync);
30
67
  */
31
68
  sync: (req: Request, res: Response) => void;
32
69
  /**
33
- * Handles snapshot GET requests for Express.
34
- * @param {Request} req - Express request object.
35
- * @param {Response} res - Express response object.
70
+ * Snapshot GET handler.
71
+ * Usage: app.get('/custom/snapshot', zuno.snapshot);
36
72
  */
37
73
  snapshot: (req: Request, res: Response) => void;
38
74
  };
39
75
 
40
- export { type CreateZunoExpressOptions, createZunoExpress };
76
+ export { type CreateZunoExpressOptions, createZunoExpress, mountZuno };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { IncomingHttpHeaders } from 'node:http';
1
2
  import { Request, Response } from 'express';
2
- import { IncomingHttpHeaders } from 'http';
3
3
 
4
4
  /**
5
5
  * Options for creating an Express router for Zuno.
@@ -10,31 +10,67 @@ type CreateZunoExpressOptions = {
10
10
  };
11
11
  /**
12
12
  * Creates a Zuno Express instance.
13
- * @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.
14
- * @returns {Object} An object with the following properties:
15
- * - sse: An Express handler function that handles SSE connections.
16
- * - sync: An Express handler function that handles sync POST requests.
17
- * - snapshot: An Express handler function that handles snapshot GET requests.
13
+ * Returns both granular handlers and a convenience `mount` helper.
18
14
  */
19
15
  declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
20
16
  /**
21
- * Handles SSE connections for Express.
22
- * @param {Request} req - Express request object.
23
- * @param {Response} res - Express response object.
17
+ * Optional convenience method to mount all Zuno handlers at once.
18
+ * @param app The Express App or Router to mount the handlers on.
19
+ * @param basePath The base path for the Zuno routes (defaults to "/zuno").
20
+ */
21
+ mount: (app: {
22
+ get: Function;
23
+ post: Function;
24
+ }, basePath?: string) => void;
25
+ /**
26
+ * SSE connection handler.
27
+ * Usage: app.get('/custom/sse', zuno.sse);
28
+ */
29
+ sse: (req: Request, res: Response) => void;
30
+ /**
31
+ * Sync POST handler.
32
+ * Usage: app.post('/custom/sync', zuno.sync);
33
+ */
34
+ sync: (req: Request, res: Response) => void;
35
+ /**
36
+ * Snapshot GET handler.
37
+ * Usage: app.get('/custom/snapshot', zuno.snapshot);
38
+ */
39
+ snapshot: (req: Request, res: Response) => void;
40
+ };
41
+ /**
42
+ * A standalone helper to mount Zuno handlers on an Express app/router.
43
+ */
44
+ declare function mountZuno(app: {
45
+ get: Function;
46
+ post: Function;
47
+ }, opts?: CreateZunoExpressOptions & {
48
+ basePath?: string;
49
+ }): {
50
+ /**
51
+ * Optional convenience method to mount all Zuno handlers at once.
52
+ * @param app The Express App or Router to mount the handlers on.
53
+ * @param basePath The base path for the Zuno routes (defaults to "/zuno").
54
+ */
55
+ mount: (app: {
56
+ get: Function;
57
+ post: Function;
58
+ }, basePath?: string) => void;
59
+ /**
60
+ * SSE connection handler.
61
+ * Usage: app.get('/custom/sse', zuno.sse);
24
62
  */
25
63
  sse: (req: Request, res: Response) => void;
26
64
  /**
27
- * Handles sync POST requests for Express.
28
- * @param {Request} req - Express request object.
29
- * @param {Response} res - Express response object.
65
+ * Sync POST handler.
66
+ * Usage: app.post('/custom/sync', zuno.sync);
30
67
  */
31
68
  sync: (req: Request, res: Response) => void;
32
69
  /**
33
- * Handles snapshot GET requests for Express.
34
- * @param {Request} req - Express request object.
35
- * @param {Response} res - Express response object.
70
+ * Snapshot GET handler.
71
+ * Usage: app.get('/custom/snapshot', zuno.snapshot);
36
72
  */
37
73
  snapshot: (req: Request, res: Response) => void;
38
74
  };
39
75
 
40
- export { type CreateZunoExpressOptions, createZunoExpress };
76
+ export { type CreateZunoExpressOptions, createZunoExpress, mountZuno };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var server=require('@iadev93/zuno/server');function c(n){let{headers:o}=n??{};return {sse:(t,e)=>server.createSSEConnection(t,e,o??{}),sync:(t,e)=>{let r=t.body,s=server.applyStateEvent(r);if(!s.ok){e.status(409).json({reason:s.reason,current:s.current});return}e.status(200).json({ok:true,event:s.event});},snapshot:(t,e)=>server.sendSnapshot(t,e)}}exports.createZunoExpress=c;//# sourceMappingURL=index.js.map
1
+ 'use strict';var server=require('@iadev93/zuno/server');function i(o){let{headers:r={}}=o??{},n={sse:(e,t)=>server.createSSEConnection(e,t,r),sync:(e,t)=>{let u=e.body,s=server.applyStateEvent(u);if(!s.ok){t.status(409).json({ok:false,reason:s.reason,current:s.current});return}t.status(200).json({ok:true,event:s.event});},snapshot:(e,t)=>server.sendSnapshot(e,t)};return {...n,mount:(e,t="/zuno")=>{e.get(`${t}/sse`,n.sse),e.get(`${t}/snapshot`,n.snapshot),e.post(`${t}/sync`,n.sync);}}}function d(o,r){let{basePath:n="/zuno",...e}=r??{},t=i(e);return t.mount(o,n),t}exports.createZunoExpress=i;exports.mountZuno=d;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["createZunoExpress","opts","headers","req","res","createSSEConnection","incoming","result","applyStateEvent","sendSnapshot"],"mappings":"wDAyBO,SAASA,CAAAA,CAAkBC,EAAiC,CAClE,GAAM,CAAE,OAAA,CAAAC,CAAQ,EAAID,CAAAA,EAAQ,GAE5B,OAAO,CAMN,GAAA,CAAK,CAACE,EAAcC,CAAAA,GACnBC,0BAAAA,CAAoBF,EAAKC,CAAAA,CAAKF,CAAAA,EAAW,EAAE,CAAA,CAO5C,KAAM,CAACC,CAAAA,CAAcC,IAAkB,CACtC,IAAME,EAAWH,CAAAA,CAAI,IAAA,CACfI,EAASC,sBAAAA,CAAgBF,CAAQ,CAAA,CAEvC,GAAI,CAACC,CAAAA,CAAO,EAAA,CAAI,CACfH,CAAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,CACpB,MAAA,CAAQG,CAAAA,CAAO,OACf,OAAA,CAASA,CAAAA,CAAO,OACjB,CAAC,CAAA,CACD,MACD,CAEAH,CAAAA,CAAI,MAAA,CAAO,GAAG,EAAE,IAAA,CAAK,CAAE,GAAI,IAAA,CAAM,KAAA,CAAOG,EAAO,KAAM,CAAC,EACvD,CAAA,CAOA,QAAA,CAAU,CAACJ,CAAAA,CAAcC,CAAAA,GAAkBK,oBAAaN,CAAAA,CAAKC,CAAG,CACjE,CACD","file":"index.js","sourcesContent":["import type { ZunoStateEvent } from \"@iadev93/zuno\";\nimport {\n\tapplyStateEvent,\n\tcreateSSEConnection,\n\tsendSnapshot,\n} from \"@iadev93/zuno/server\";\nimport type { Request, Response } from \"express\";\nimport type { IncomingHttpHeaders } from \"http\";\n\n/**\n * Options for creating an Express router for Zuno.\n */\nexport type CreateZunoExpressOptions = {\n\t/** Optional custom headers to be sent with the SSE response. */\n\theaders?: IncomingHttpHeaders;\n};\n\n/**\n * Creates a Zuno Express instance.\n * @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.\n * @returns {Object} An object with the following properties:\n * - sse: An Express handler function that handles SSE connections.\n * - sync: An Express handler function that handles sync POST requests.\n * - snapshot: An Express handler function that handles snapshot GET requests.\n */\nexport function createZunoExpress(opts?: CreateZunoExpressOptions) {\n\tconst { headers } = opts ?? {};\n\n\treturn {\n\t\t/**\n\t\t * Handles SSE connections for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsse: (req: Request, res: Response) =>\n\t\t\tcreateSSEConnection(req, res, headers ?? {}),\n\n\t\t/**\n\t\t * Handles sync POST requests for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsync: (req: Request, res: Response) => {\n\t\t\tconst incoming = req.body as ZunoStateEvent;\n\t\t\tconst result = applyStateEvent(incoming);\n\n\t\t\tif (!result.ok) {\n\t\t\t\tres.status(409).json({\n\t\t\t\t\treason: result.reason,\n\t\t\t\t\tcurrent: result.current,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.status(200).json({ ok: true, event: result.event });\n\t\t},\n\n\t\t/**\n\t\t * Handles snapshot GET requests for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsnapshot: (req: Request, res: Response) => sendSnapshot(req, res),\n\t};\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["createZunoExpress","opts","headers","handlers","req","res","createSSEConnection","incoming","result","applyStateEvent","sendSnapshot","app","basePath","mountZuno","rest","zuno"],"mappings":"wDAqBO,SAASA,CAAAA,CAAkBC,EAAiC,CAClE,GAAM,CAAE,OAAA,CAAAC,EAAU,EAAG,CAAA,CAAID,CAAAA,EAAQ,EAAC,CAM5BE,CAAAA,CAAW,CAKhB,GAAA,CAAK,CAACC,CAAAA,CAAcC,CAAAA,GACnBC,0BAAAA,CAAoBF,CAAAA,CAAKC,EAAKH,CAAO,CAAA,CAMtC,IAAA,CAAM,CAACE,EAAcC,CAAAA,GAAkB,CACtC,IAAME,CAAAA,CAAWH,EAAI,IAAA,CACfI,CAAAA,CAASC,sBAAAA,CAAgBF,CAAQ,EAEvC,GAAI,CAACC,CAAAA,CAAO,EAAA,CAAI,CACfH,CAAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,KAAK,CACpB,EAAA,CAAI,KAAA,CACJ,MAAA,CAAQG,EAAO,MAAA,CACf,OAAA,CAASA,CAAAA,CAAO,OACjB,CAAC,CAAA,CACD,MACD,CAEAH,CAAAA,CAAI,OAAO,GAAG,CAAA,CAAE,IAAA,CAAK,CAAE,GAAI,IAAA,CAAM,KAAA,CAAOG,CAAAA,CAAO,KAAM,CAAC,EACvD,CAAA,CAMA,QAAA,CAAU,CAACJ,CAAAA,CAAcC,CAAAA,GAAkBK,mBAAAA,CAAaN,CAAAA,CAAKC,CAAG,CACjE,CAAA,CAEA,OAAO,CACN,GAAGF,CAAAA,CAMH,KAAA,CAAO,CAACQ,CAAAA,CAAwCC,EAAW,OAAA,GAAY,CACtED,CAAAA,CAAI,GAAA,CAAI,GAAGC,CAAQ,CAAA,IAAA,CAAA,CAAQT,CAAAA,CAAS,GAAG,EACvCQ,CAAAA,CAAI,GAAA,CAAI,CAAA,EAAGC,CAAQ,YAAaT,CAAAA,CAAS,QAAQ,CAAA,CACjDQ,CAAAA,CAAI,KAAK,CAAA,EAAGC,CAAQ,CAAA,KAAA,CAAA,CAAST,CAAAA,CAAS,IAAI,EAC3C,CACD,CACD,CAKO,SAASU,CAAAA,CACfF,CAAAA,CACAV,CAAAA,CACC,CACD,GAAM,CAAE,QAAA,CAAAW,CAAAA,CAAW,OAAA,CAAS,GAAGE,CAAK,CAAA,CAAIb,CAAAA,EAAQ,GAC1Cc,CAAAA,CAAOf,CAAAA,CAAkBc,CAAI,CAAA,CACnC,OAAAC,CAAAA,CAAK,KAAA,CAAMJ,CAAAA,CAAKC,CAAQ,EACjBG,CACR","file":"index.js","sourcesContent":["import type { IncomingHttpHeaders } from \"node:http\";\nimport type { ZunoStateEvent } from \"@iadev93/zuno\";\nimport {\n\tapplyStateEvent,\n\tcreateSSEConnection,\n\tsendSnapshot,\n} from \"@iadev93/zuno/server\";\nimport type { Request, Response } from \"express\";\n\n/**\n * Options for creating an Express router for Zuno.\n */\nexport type CreateZunoExpressOptions = {\n\t/** Optional custom headers to be sent with the SSE response. */\n\theaders?: IncomingHttpHeaders;\n};\n\n/**\n * Creates a Zuno Express instance.\n * Returns both granular handlers and a convenience `mount` helper.\n */\nexport function createZunoExpress(opts?: CreateZunoExpressOptions) {\n\tconst { headers = {} } = opts ?? {};\n\n\t/**\n\t * Granular handlers for maximum control.\n\t * You can mount these manually to any route or wrap them in custom middleware.\n\t */\n\tconst handlers = {\n\t\t/**\n\t\t * SSE connection handler.\n\t\t * Usage: app.get('/custom/sse', zuno.sse);\n\t\t */\n\t\tsse: (req: Request, res: Response) =>\n\t\t\tcreateSSEConnection(req, res, headers),\n\n\t\t/**\n\t\t * Sync POST handler.\n\t\t * Usage: app.post('/custom/sync', zuno.sync);\n\t\t */\n\t\tsync: (req: Request, res: Response) => {\n\t\t\tconst incoming = req.body as ZunoStateEvent;\n\t\t\tconst result = applyStateEvent(incoming);\n\n\t\t\tif (!result.ok) {\n\t\t\t\tres.status(409).json({\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: result.reason,\n\t\t\t\t\tcurrent: result.current,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.status(200).json({ ok: true, event: result.event });\n\t\t},\n\n\t\t/**\n\t\t * Snapshot GET handler.\n\t\t * Usage: app.get('/custom/snapshot', zuno.snapshot);\n\t\t */\n\t\tsnapshot: (req: Request, res: Response) => sendSnapshot(req, res),\n\t};\n\n\treturn {\n\t\t...handlers,\n\t\t/**\n\t\t * Optional convenience method to mount all Zuno handlers at once.\n\t\t * @param app The Express App or Router to mount the handlers on.\n\t\t * @param basePath The base path for the Zuno routes (defaults to \"/zuno\").\n\t\t */\n\t\tmount: (app: { get: Function; post: Function }, basePath = \"/zuno\") => {\n\t\t\tapp.get(`${basePath}/sse`, handlers.sse);\n\t\t\tapp.get(`${basePath}/snapshot`, handlers.snapshot);\n\t\t\tapp.post(`${basePath}/sync`, handlers.sync);\n\t\t},\n\t};\n}\n\n/**\n * A standalone helper to mount Zuno handlers on an Express app/router.\n */\nexport function mountZuno(\n\tapp: { get: Function; post: Function },\n\topts?: CreateZunoExpressOptions & { basePath?: string },\n) {\n\tconst { basePath = \"/zuno\", ...rest } = opts ?? {};\n\tconst zuno = createZunoExpress(rest);\n\tzuno.mount(app, basePath);\n\treturn zuno;\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {sendSnapshot,createSSEConnection,applyStateEvent}from'@iadev93/zuno/server';function c(n){let{headers:o}=n??{};return {sse:(t,e)=>createSSEConnection(t,e,o??{}),sync:(t,e)=>{let r=t.body,s=applyStateEvent(r);if(!s.ok){e.status(409).json({reason:s.reason,current:s.current});return}e.status(200).json({ok:true,event:s.event});},snapshot:(t,e)=>sendSnapshot(t,e)}}export{c as createZunoExpress};//# sourceMappingURL=index.mjs.map
1
+ import {sendSnapshot,createSSEConnection,applyStateEvent}from'@iadev93/zuno/server';function i(o){let{headers:r={}}=o??{},n={sse:(e,t)=>createSSEConnection(e,t,r),sync:(e,t)=>{let u=e.body,s=applyStateEvent(u);if(!s.ok){t.status(409).json({ok:false,reason:s.reason,current:s.current});return}t.status(200).json({ok:true,event:s.event});},snapshot:(e,t)=>sendSnapshot(e,t)};return {...n,mount:(e,t="/zuno")=>{e.get(`${t}/sse`,n.sse),e.get(`${t}/snapshot`,n.snapshot),e.post(`${t}/sync`,n.sync);}}}function d(o,r){let{basePath:n="/zuno",...e}=r??{},t=i(e);return t.mount(o,n),t}export{i as createZunoExpress,d as mountZuno};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["createZunoExpress","opts","headers","req","res","createSSEConnection","incoming","result","applyStateEvent","sendSnapshot"],"mappings":"oFAyBO,SAASA,CAAAA,CAAkBC,EAAiC,CAClE,GAAM,CAAE,OAAA,CAAAC,CAAQ,EAAID,CAAAA,EAAQ,GAE5B,OAAO,CAMN,GAAA,CAAK,CAACE,EAAcC,CAAAA,GACnBC,mBAAAA,CAAoBF,EAAKC,CAAAA,CAAKF,CAAAA,EAAW,EAAE,CAAA,CAO5C,KAAM,CAACC,CAAAA,CAAcC,IAAkB,CACtC,IAAME,EAAWH,CAAAA,CAAI,IAAA,CACfI,EAASC,eAAAA,CAAgBF,CAAQ,CAAA,CAEvC,GAAI,CAACC,CAAAA,CAAO,EAAA,CAAI,CACfH,CAAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,CACpB,MAAA,CAAQG,CAAAA,CAAO,OACf,OAAA,CAASA,CAAAA,CAAO,OACjB,CAAC,CAAA,CACD,MACD,CAEAH,CAAAA,CAAI,MAAA,CAAO,GAAG,EAAE,IAAA,CAAK,CAAE,GAAI,IAAA,CAAM,KAAA,CAAOG,EAAO,KAAM,CAAC,EACvD,CAAA,CAOA,QAAA,CAAU,CAACJ,CAAAA,CAAcC,CAAAA,GAAkBK,aAAaN,CAAAA,CAAKC,CAAG,CACjE,CACD","file":"index.mjs","sourcesContent":["import type { ZunoStateEvent } from \"@iadev93/zuno\";\nimport {\n\tapplyStateEvent,\n\tcreateSSEConnection,\n\tsendSnapshot,\n} from \"@iadev93/zuno/server\";\nimport type { Request, Response } from \"express\";\nimport type { IncomingHttpHeaders } from \"http\";\n\n/**\n * Options for creating an Express router for Zuno.\n */\nexport type CreateZunoExpressOptions = {\n\t/** Optional custom headers to be sent with the SSE response. */\n\theaders?: IncomingHttpHeaders;\n};\n\n/**\n * Creates a Zuno Express instance.\n * @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.\n * @returns {Object} An object with the following properties:\n * - sse: An Express handler function that handles SSE connections.\n * - sync: An Express handler function that handles sync POST requests.\n * - snapshot: An Express handler function that handles snapshot GET requests.\n */\nexport function createZunoExpress(opts?: CreateZunoExpressOptions) {\n\tconst { headers } = opts ?? {};\n\n\treturn {\n\t\t/**\n\t\t * Handles SSE connections for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsse: (req: Request, res: Response) =>\n\t\t\tcreateSSEConnection(req, res, headers ?? {}),\n\n\t\t/**\n\t\t * Handles sync POST requests for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsync: (req: Request, res: Response) => {\n\t\t\tconst incoming = req.body as ZunoStateEvent;\n\t\t\tconst result = applyStateEvent(incoming);\n\n\t\t\tif (!result.ok) {\n\t\t\t\tres.status(409).json({\n\t\t\t\t\treason: result.reason,\n\t\t\t\t\tcurrent: result.current,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.status(200).json({ ok: true, event: result.event });\n\t\t},\n\n\t\t/**\n\t\t * Handles snapshot GET requests for Express.\n\t\t * @param {Request} req - Express request object.\n\t\t * @param {Response} res - Express response object.\n\t\t */\n\t\tsnapshot: (req: Request, res: Response) => sendSnapshot(req, res),\n\t};\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["createZunoExpress","opts","headers","handlers","req","res","createSSEConnection","incoming","result","applyStateEvent","sendSnapshot","app","basePath","mountZuno","rest","zuno"],"mappings":"oFAqBO,SAASA,CAAAA,CAAkBC,EAAiC,CAClE,GAAM,CAAE,OAAA,CAAAC,EAAU,EAAG,CAAA,CAAID,CAAAA,EAAQ,EAAC,CAM5BE,CAAAA,CAAW,CAKhB,GAAA,CAAK,CAACC,CAAAA,CAAcC,CAAAA,GACnBC,mBAAAA,CAAoBF,CAAAA,CAAKC,EAAKH,CAAO,CAAA,CAMtC,IAAA,CAAM,CAACE,EAAcC,CAAAA,GAAkB,CACtC,IAAME,CAAAA,CAAWH,EAAI,IAAA,CACfI,CAAAA,CAASC,eAAAA,CAAgBF,CAAQ,EAEvC,GAAI,CAACC,CAAAA,CAAO,EAAA,CAAI,CACfH,CAAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,KAAK,CACpB,EAAA,CAAI,KAAA,CACJ,MAAA,CAAQG,EAAO,MAAA,CACf,OAAA,CAASA,CAAAA,CAAO,OACjB,CAAC,CAAA,CACD,MACD,CAEAH,CAAAA,CAAI,OAAO,GAAG,CAAA,CAAE,IAAA,CAAK,CAAE,GAAI,IAAA,CAAM,KAAA,CAAOG,CAAAA,CAAO,KAAM,CAAC,EACvD,CAAA,CAMA,QAAA,CAAU,CAACJ,CAAAA,CAAcC,CAAAA,GAAkBK,YAAAA,CAAaN,CAAAA,CAAKC,CAAG,CACjE,CAAA,CAEA,OAAO,CACN,GAAGF,CAAAA,CAMH,KAAA,CAAO,CAACQ,CAAAA,CAAwCC,EAAW,OAAA,GAAY,CACtED,CAAAA,CAAI,GAAA,CAAI,GAAGC,CAAQ,CAAA,IAAA,CAAA,CAAQT,CAAAA,CAAS,GAAG,EACvCQ,CAAAA,CAAI,GAAA,CAAI,CAAA,EAAGC,CAAQ,YAAaT,CAAAA,CAAS,QAAQ,CAAA,CACjDQ,CAAAA,CAAI,KAAK,CAAA,EAAGC,CAAQ,CAAA,KAAA,CAAA,CAAST,CAAAA,CAAS,IAAI,EAC3C,CACD,CACD,CAKO,SAASU,CAAAA,CACfF,CAAAA,CACAV,CAAAA,CACC,CACD,GAAM,CAAE,QAAA,CAAAW,CAAAA,CAAW,OAAA,CAAS,GAAGE,CAAK,CAAA,CAAIb,CAAAA,EAAQ,GAC1Cc,CAAAA,CAAOf,CAAAA,CAAkBc,CAAI,CAAA,CACnC,OAAAC,CAAAA,CAAK,KAAA,CAAMJ,CAAAA,CAAKC,CAAQ,EACjBG,CACR","file":"index.mjs","sourcesContent":["import type { IncomingHttpHeaders } from \"node:http\";\nimport type { ZunoStateEvent } from \"@iadev93/zuno\";\nimport {\n\tapplyStateEvent,\n\tcreateSSEConnection,\n\tsendSnapshot,\n} from \"@iadev93/zuno/server\";\nimport type { Request, Response } from \"express\";\n\n/**\n * Options for creating an Express router for Zuno.\n */\nexport type CreateZunoExpressOptions = {\n\t/** Optional custom headers to be sent with the SSE response. */\n\theaders?: IncomingHttpHeaders;\n};\n\n/**\n * Creates a Zuno Express instance.\n * Returns both granular handlers and a convenience `mount` helper.\n */\nexport function createZunoExpress(opts?: CreateZunoExpressOptions) {\n\tconst { headers = {} } = opts ?? {};\n\n\t/**\n\t * Granular handlers for maximum control.\n\t * You can mount these manually to any route or wrap them in custom middleware.\n\t */\n\tconst handlers = {\n\t\t/**\n\t\t * SSE connection handler.\n\t\t * Usage: app.get('/custom/sse', zuno.sse);\n\t\t */\n\t\tsse: (req: Request, res: Response) =>\n\t\t\tcreateSSEConnection(req, res, headers),\n\n\t\t/**\n\t\t * Sync POST handler.\n\t\t * Usage: app.post('/custom/sync', zuno.sync);\n\t\t */\n\t\tsync: (req: Request, res: Response) => {\n\t\t\tconst incoming = req.body as ZunoStateEvent;\n\t\t\tconst result = applyStateEvent(incoming);\n\n\t\t\tif (!result.ok) {\n\t\t\t\tres.status(409).json({\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: result.reason,\n\t\t\t\t\tcurrent: result.current,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.status(200).json({ ok: true, event: result.event });\n\t\t},\n\n\t\t/**\n\t\t * Snapshot GET handler.\n\t\t * Usage: app.get('/custom/snapshot', zuno.snapshot);\n\t\t */\n\t\tsnapshot: (req: Request, res: Response) => sendSnapshot(req, res),\n\t};\n\n\treturn {\n\t\t...handlers,\n\t\t/**\n\t\t * Optional convenience method to mount all Zuno handlers at once.\n\t\t * @param app The Express App or Router to mount the handlers on.\n\t\t * @param basePath The base path for the Zuno routes (defaults to \"/zuno\").\n\t\t */\n\t\tmount: (app: { get: Function; post: Function }, basePath = \"/zuno\") => {\n\t\t\tapp.get(`${basePath}/sse`, handlers.sse);\n\t\t\tapp.get(`${basePath}/snapshot`, handlers.snapshot);\n\t\t\tapp.post(`${basePath}/sync`, handlers.sync);\n\t\t},\n\t};\n}\n\n/**\n * A standalone helper to mount Zuno handlers on an Express app/router.\n */\nexport function mountZuno(\n\tapp: { get: Function; post: Function },\n\topts?: CreateZunoExpressOptions & { basePath?: string },\n) {\n\tconst { basePath = \"/zuno\", ...rest } = opts ?? {};\n\tconst zuno = createZunoExpress(rest);\n\tzuno.mount(app, basePath);\n\treturn zuno;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iadev93/zuno-express",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -16,14 +16,14 @@
16
16
  },
17
17
  "peerDependencies": {
18
18
  "express": "^5.0.0",
19
- "@iadev93/zuno": "0.0.8"
19
+ "@iadev93/zuno": "0.0.9"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/express": "^5.0.0",
23
23
  "@types/node": "^20.0.0",
24
24
  "tsup": "^8.5.1",
25
25
  "typescript": "^5.9.3",
26
- "@iadev93/zuno": "0.0.8"
26
+ "@iadev93/zuno": "0.0.9"
27
27
  },
28
28
  "keywords": [
29
29
  "zuno",