@iadev93/zuno-express 0.0.6 → 0.0.7
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/LICENSE +9 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -1
- package/package.json +13 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ibrahim Aftab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Request, Response } from "express";
|
|
2
|
+
import type { IncomingHttpHeaders } from "http";
|
|
3
|
+
/**
|
|
4
|
+
* Options for creating an Express router for Zuno.
|
|
5
|
+
*/
|
|
6
|
+
export type CreateZunoExpressOptions = {
|
|
7
|
+
/** Optional custom headers to be sent with the SSE response. */
|
|
8
|
+
headers?: IncomingHttpHeaders;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Zuno Express instance.
|
|
12
|
+
* @param {CreateZunoExpressOptions} [opts] - Options for creating the Express router.
|
|
13
|
+
* @returns {Object} An object with the following properties:
|
|
14
|
+
* - sse: An Express handler function that handles SSE connections.
|
|
15
|
+
* - sync: An Express handler function that handles sync POST requests.
|
|
16
|
+
* - snapshot: An Express handler function that handles snapshot GET requests.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
|
|
19
|
+
/**
|
|
20
|
+
* Handles SSE connections for Express.
|
|
21
|
+
* @param {Request} req - Express request object.
|
|
22
|
+
* @param {Response} res - Express response object.
|
|
23
|
+
*/
|
|
24
|
+
sse: (req: Request, res: Response) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Handles sync POST requests for Express.
|
|
27
|
+
* @param {Request} req - Express request object.
|
|
28
|
+
* @param {Response} res - Express response object.
|
|
29
|
+
*/
|
|
30
|
+
sync: (req: Request, res: Response) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Handles snapshot GET requests for Express.
|
|
33
|
+
* @param {Request} req - Express request object.
|
|
34
|
+
* @param {Response} res - Express response object.
|
|
35
|
+
*/
|
|
36
|
+
snapshot: (req: Request, res: Response) => void;
|
|
37
|
+
};
|
|
2
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import { createSSEConnection, applyStateEvent, sendSnapshot } from "@iadev93/zuno/server";
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iadev93/zuno-express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
|
-
"README.md"
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
9
10
|
],
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
@@ -13,20 +14,19 @@
|
|
|
13
14
|
"default": "./dist/index.js"
|
|
14
15
|
}
|
|
15
16
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsc -p tsconfig.json"
|
|
18
|
-
},
|
|
19
17
|
"peerDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
18
|
+
"express": "^5.0.0",
|
|
19
|
+
"@iadev93/zuno": "0.0.5"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
22
|
"@types/express": "^5.0.0",
|
|
25
23
|
"@types/node": "^20.0.0",
|
|
26
24
|
"typescript": "^5.9.3",
|
|
27
|
-
"@iadev93/zuno": "
|
|
25
|
+
"@iadev93/zuno": "0.0.5"
|
|
28
26
|
},
|
|
29
27
|
"keywords": [
|
|
28
|
+
"zuno",
|
|
29
|
+
"express",
|
|
30
30
|
"state",
|
|
31
31
|
"state-management",
|
|
32
32
|
"sync",
|
|
@@ -44,5 +44,8 @@
|
|
|
44
44
|
"url": "git+https://github.com/IADev-Channel/zuno.git"
|
|
45
45
|
},
|
|
46
46
|
"author": "Ibrahim Aftab",
|
|
47
|
-
"license": "MIT"
|
|
48
|
-
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.json"
|
|
50
|
+
}
|
|
51
|
+
}
|