@iadev93/zuno-express 0.0.6 → 0.0.8

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 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
- export * from './createZunoExpress';
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
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
- export * from './createZunoExpress';
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.6",
3
+ "version": "0.0.8",
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
- "@iadev93/zuno": "workspace:*",
21
- "express": "^5.0.0"
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": "workspace:*"
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
+ }
@@ -1,29 +0,0 @@
1
- import type { IncomingHttpHeaders } from "http";
2
- /**
3
- * Options for creating an Express router for Zuno.
4
- */
5
- type CreateZunoExpressOptions = {
6
- headers?: IncomingHttpHeaders;
7
- };
8
- /**
9
- * Creates an Express router for Zuno.
10
- *
11
- * @param opts - Options for creating the Express router.
12
- * @returns An object containing the SSE, sync, and snapshot handlers
13
- */
14
- export declare function createZunoExpress(opts?: CreateZunoExpressOptions): {
15
- /**
16
- * Handles SSE connections.
17
- */
18
- sse: (req: import("express").Request, res: import("express").Response) => void;
19
- /**
20
- * Handles sync connections.
21
- */
22
- sync: (req: import("express").Request, res: import("express").Response) => void;
23
- /**
24
- * Handles snapshot connections.
25
- */
26
- snapshot: (req: import("express").Request, res: import("express").Response) => void;
27
- };
28
- export {};
29
- //# sourceMappingURL=createZunoExpress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createZunoExpress.d.ts","sourceRoot":"","sources":["../src/createZunoExpress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAA;AAK/C;;GAEG;AACH,KAAK,wBAAwB,GAAG;IAC9B,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,wBAAwB;IAI7D;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;EAGN"}
@@ -1,26 +0,0 @@
1
- import { createExpressSSEHandler } from "./express-sse-handler";
2
- import { createExpressSyncHandler } from "./express-sync-handler";
3
- import { createExpressSnapshotHandler } from "./express-snapshot-handler";
4
- /**
5
- * Creates an Express router for Zuno.
6
- *
7
- * @param opts - Options for creating the Express router.
8
- * @returns An object containing the SSE, sync, and snapshot handlers
9
- */
10
- export function createZunoExpress(opts) {
11
- const { headers } = opts ?? {};
12
- return {
13
- /**
14
- * Handles SSE connections.
15
- */
16
- sse: createExpressSSEHandler(headers),
17
- /**
18
- * Handles sync connections.
19
- */
20
- sync: createExpressSyncHandler(),
21
- /**
22
- * Handles snapshot connections.
23
- */
24
- snapshot: createExpressSnapshotHandler(),
25
- };
26
- }
@@ -1,7 +0,0 @@
1
- import type { Request, Response } from "express";
2
- /**
3
- * Creates an Express handler for handling Zuno state events.
4
- * @returns An Express handler function.
5
- */
6
- export declare function createExpressSnapshotHandler(): (req: Request, res: Response) => void;
7
- //# sourceMappingURL=express-snapshot-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"express-snapshot-handler.d.ts","sourceRoot":"","sources":["../src/express-snapshot-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGhD;;;GAGG;AACH,wBAAgB,4BAA4B,KAClC,KAAK,OAAO,EAAE,KAAK,QAAQ,UACpC"}
@@ -1,8 +0,0 @@
1
- import { sendSnapshot } from "@iadev93/zuno/server";
2
- /**
3
- * Creates an Express handler for handling Zuno state events.
4
- * @returns An Express handler function.
5
- */
6
- export function createExpressSnapshotHandler() {
7
- return (req, res) => sendSnapshot(req, res);
8
- }
@@ -1,8 +0,0 @@
1
- import type { Request, Response } from "express";
2
- import type { IncomingHttpHeaders } from "http";
3
- /**
4
- * Creates an SSE handler for express.
5
- * @returns An Express handler function.
6
- */
7
- export declare function createExpressSSEHandler(headers?: IncomingHttpHeaders): (req: Request, res: Response) => void;
8
- //# sourceMappingURL=express-sse-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"express-sse-handler.d.ts","sourceRoot":"","sources":["../src/express-sse-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAIhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,mBAAmB,IAI3D,KAAK,OAAO,EAAE,KAAK,QAAQ,UACpC"}
@@ -1,11 +0,0 @@
1
- import { createSSEConnection } from "@iadev93/zuno/server";
2
- /**
3
- * Creates an SSE handler for express.
4
- * @returns An Express handler function.
5
- */
6
- export function createExpressSSEHandler(headers) {
7
- /**
8
- * Creates an SSE connection for the client.
9
- */
10
- return (req, res) => createSSEConnection(req, res, headers ?? {});
11
- }
@@ -1,7 +0,0 @@
1
- import type { Request, Response } from "express";
2
- /**
3
- * Creates an Express handler for handling Zuno state events.
4
- * @returns An Express handler function.
5
- */
6
- export declare function createExpressSyncHandler(): (req: Request, res: Response) => void;
7
- //# sourceMappingURL=express-sync-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"express-sync-handler.d.ts","sourceRoot":"","sources":["../src/express-sync-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKhD;;;GAGG;AACH,wBAAgB,wBAAwB,KAC9B,KAAK,OAAO,EAAE,KAAK,QAAQ,UAmBpC"}
@@ -1,23 +0,0 @@
1
- import { applyStateEvent } from "@iadev93/zuno/server";
2
- /**
3
- * Creates an Express handler for handling Zuno state events.
4
- * @returns An Express handler function.
5
- */
6
- export function createExpressSyncHandler() {
7
- return (req, res) => {
8
- /** The incoming state event to apply. */
9
- const incoming = req.body;
10
- /** Applies the incoming state event to the target Zuno universe or store. */
11
- const result = applyStateEvent(incoming);
12
- /** If the state event is not valid, returns a 409 status code with the reason and current state. */
13
- if (!result.ok) {
14
- res.status(409).json({
15
- reason: result.reason,
16
- current: result.current,
17
- });
18
- return;
19
- }
20
- /** Returns a 200 status code with the result. */
21
- res.status(200).json({ ok: true, event: result.event });
22
- };
23
- }