@iadev93/zuno-express 0.0.8 → 0.0.10
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 +22 -10
- package/dist/index.d.mts +40 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +2 -43
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -4
- package/dist/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @iadev93/zuno-express
|
|
2
2
|
|
|
3
|
-
Express adapter for
|
|
3
|
+
<p><b>Express adapter for Zuno.</b></p>
|
|
4
4
|
|
|
5
|
-
Provides server
|
|
5
|
+
Provides server-side synchronization endpoints using Server-Sent Events (SSE) for Express applications.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -13,7 +13,6 @@ npm install @iadev93/zuno-express
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Peer dependency:
|
|
16
|
-
|
|
17
16
|
* `express >= 4`
|
|
18
17
|
|
|
19
18
|
---
|
|
@@ -23,23 +22,36 @@ Peer dependency:
|
|
|
23
22
|
```ts
|
|
24
23
|
import express from "express";
|
|
25
24
|
import { createZunoExpress } from "@iadev93/zuno-express";
|
|
26
|
-
import { createZuno } from "@iadev93/zuno";
|
|
27
25
|
|
|
28
26
|
const app = express();
|
|
29
|
-
|
|
27
|
+
app.use(express.json());
|
|
28
|
+
|
|
29
|
+
const zuno = createZunoExpress();
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// Unified handlers
|
|
32
|
+
app.get("/zuno/sse", zuno.sse);
|
|
33
|
+
app.post("/zuno/sync", zuno.sync);
|
|
34
|
+
app.get("/zuno/snapshot", zuno.snapshot);
|
|
32
35
|
|
|
33
36
|
app.listen(3000);
|
|
34
37
|
```
|
|
35
38
|
|
|
36
39
|
---
|
|
37
40
|
|
|
38
|
-
##
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### `createZunoExpress(opts?)`
|
|
44
|
+
|
|
45
|
+
Returns an object containing the following Express handlers:
|
|
46
|
+
|
|
47
|
+
#### `sse` (GET)
|
|
48
|
+
Handles persistent SSE connections, heartbeats, and initial synchronization.
|
|
49
|
+
|
|
50
|
+
#### `sync` (POST)
|
|
51
|
+
Validates and applies incoming state events.
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* Version‑safe event ingestion
|
|
53
|
+
#### `snapshot` (GET)
|
|
54
|
+
Returns the current full state of the universe.
|
|
43
55
|
|
|
44
56
|
---
|
|
45
57
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { IncomingHttpHeaders } from 'http';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for creating an Express router for Zuno.
|
|
6
|
+
*/
|
|
7
|
+
type CreateZunoExpressOptions = {
|
|
8
|
+
/** Optional custom headers to be sent with the SSE response. */
|
|
9
|
+
headers?: IncomingHttpHeaders;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
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.
|
|
18
|
+
*/
|
|
19
|
+
declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
|
|
20
|
+
/**
|
|
21
|
+
* Handles SSE connections for Express.
|
|
22
|
+
* @param {Request} req - Express request object.
|
|
23
|
+
* @param {Response} res - Express response object.
|
|
24
|
+
*/
|
|
25
|
+
sse: (req: Request, res: Response) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Handles sync POST requests for Express.
|
|
28
|
+
* @param {Request} req - Express request object.
|
|
29
|
+
* @param {Response} res - Express response object.
|
|
30
|
+
*/
|
|
31
|
+
sync: (req: Request, res: Response) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Handles snapshot GET requests for Express.
|
|
34
|
+
* @param {Request} req - Express request object.
|
|
35
|
+
* @param {Response} res - Express response object.
|
|
36
|
+
*/
|
|
37
|
+
snapshot: (req: Request, res: Response) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { type CreateZunoExpressOptions, createZunoExpress };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { IncomingHttpHeaders } from 'http';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Options for creating an Express router for Zuno.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
type CreateZunoExpressOptions = {
|
|
7
8
|
/** Optional custom headers to be sent with the SSE response. */
|
|
8
9
|
headers?: IncomingHttpHeaders;
|
|
9
10
|
};
|
|
@@ -15,7 +16,7 @@ export type CreateZunoExpressOptions = {
|
|
|
15
16
|
* - sync: An Express handler function that handles sync POST requests.
|
|
16
17
|
* - snapshot: An Express handler function that handles snapshot GET requests.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
|
|
19
20
|
/**
|
|
20
21
|
* Handles SSE connections for Express.
|
|
21
22
|
* @param {Request} req - Express request object.
|
|
@@ -35,4 +36,5 @@ export declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
|
|
|
35
36
|
*/
|
|
36
37
|
snapshot: (req: Request, res: Response) => void;
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
+
|
|
40
|
+
export { type CreateZunoExpressOptions, createZunoExpress };
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Creates a Zuno Express instance.
|
|
4
|
-
* @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.
|
|
5
|
-
* @returns {Object} An object with the following properties:
|
|
6
|
-
* - sse: An Express handler function that handles SSE connections.
|
|
7
|
-
* - sync: An Express handler function that handles sync POST requests.
|
|
8
|
-
* - snapshot: An Express handler function that handles snapshot GET requests.
|
|
9
|
-
*/
|
|
10
|
-
export function createZunoExpress(opts) {
|
|
11
|
-
const { headers } = opts ?? {};
|
|
12
|
-
return {
|
|
13
|
-
/**
|
|
14
|
-
* Handles SSE connections for Express.
|
|
15
|
-
* @param {Request} req - Express request object.
|
|
16
|
-
* @param {Response} res - Express response object.
|
|
17
|
-
*/
|
|
18
|
-
sse: (req, res) => createSSEConnection(req, res, headers ?? {}),
|
|
19
|
-
/**
|
|
20
|
-
* Handles sync POST requests for Express.
|
|
21
|
-
* @param {Request} req - Express request object.
|
|
22
|
-
* @param {Response} res - Express response object.
|
|
23
|
-
*/
|
|
24
|
-
sync: (req, res) => {
|
|
25
|
-
const incoming = req.body;
|
|
26
|
-
const result = applyStateEvent(incoming);
|
|
27
|
-
if (!result.ok) {
|
|
28
|
-
res.status(409).json({
|
|
29
|
-
reason: result.reason,
|
|
30
|
-
current: result.current,
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
res.status(200).json({ ok: true, event: result.event });
|
|
35
|
-
},
|
|
36
|
-
/**
|
|
37
|
-
* Handles snapshot GET requests for Express.
|
|
38
|
-
* @param {Request} req - Express request object.
|
|
39
|
-
* @param {Response} res - Express response object.
|
|
40
|
-
*/
|
|
41
|
-
snapshot: (req, res) => sendSnapshot(req, res),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
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
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +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
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iadev93/zuno-express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"express": "^5.0.0",
|
|
19
|
-
"@iadev93/zuno": "0.0.
|
|
19
|
+
"@iadev93/zuno": "0.0.8"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/express": "^5.0.0",
|
|
23
23
|
"@types/node": "^20.0.0",
|
|
24
|
+
"tsup": "^8.5.1",
|
|
24
25
|
"typescript": "^5.9.3",
|
|
25
|
-
"@iadev93/zuno": "0.0.
|
|
26
|
+
"@iadev93/zuno": "0.0.8"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"zuno",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"author": "Ibrahim Aftab",
|
|
47
48
|
"license": "MIT",
|
|
48
49
|
"scripts": {
|
|
49
|
-
"build": "
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsup --watch"
|
|
50
52
|
}
|
|
51
53
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAQhD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,gEAAgE;IAChE,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,wBAAwB;IAI7D;;;;OAIG;eACQ,OAAO,OAAO,QAAQ;IAEjC;;;;OAIG;gBACS,OAAO,OAAO,QAAQ;IAelC;;;;OAIG;oBACa,OAAO,OAAO,QAAQ;EAEzC"}
|