@iadev93/zuno-express 0.0.3 → 0.0.5
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/createZunoExpress.d.ts +29 -0
- package/dist/createZunoExpress.d.ts.map +1 -0
- package/dist/createZunoExpress.js +26 -0
- package/dist/express-snapshot-handler.d.ts +7 -0
- package/dist/express-snapshot-handler.d.ts.map +1 -0
- package/dist/express-snapshot-handler.js +8 -0
- package/dist/express-sse-handler.d.ts +8 -0
- package/dist/express-sse-handler.d.ts.map +1 -0
- package/dist/express-sse-handler.js +11 -0
- package/dist/express-sync-handler.d.ts +7 -0
- package/dist/express-sync-handler.d.ts.map +1 -0
- package/dist/express-sync-handler.js +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +25 -2
- package/src/createZunoExpress.ts +0 -36
- package/src/express-snapshot-handler.ts +0 -10
- package/src/express-sse-handler.ts +0 -15
- package/src/express-sync-handler.ts +0 -30
- package/tsconfig.json +0 -15
- /package/{src/index.ts → dist/index.js} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iadev93/zuno-express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
6
10
|
"exports": {
|
|
7
11
|
".": {
|
|
8
12
|
"types": "./dist/index.d.ts",
|
|
@@ -21,5 +25,24 @@
|
|
|
21
25
|
"@types/node": "^20.0.0",
|
|
22
26
|
"typescript": "^5.9.3",
|
|
23
27
|
"@iadev93/zuno": "workspace:*"
|
|
24
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"state",
|
|
31
|
+
"state-management",
|
|
32
|
+
"sync",
|
|
33
|
+
"sse",
|
|
34
|
+
"server-sent-events",
|
|
35
|
+
"broadcastchannel",
|
|
36
|
+
"distributed-state",
|
|
37
|
+
"event-sourcing",
|
|
38
|
+
"universal-state",
|
|
39
|
+
"realtime"
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://github.com/IADev-Channel/zuno",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/IADev-Channel/zuno.git"
|
|
45
|
+
},
|
|
46
|
+
"author": "Ibrahim Aftab",
|
|
47
|
+
"license": "MIT"
|
|
25
48
|
}
|
package/src/createZunoExpress.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders } from "http"
|
|
2
|
-
import { createExpressSSEHandler } from "./express-sse-handler"
|
|
3
|
-
import { createExpressSyncHandler } from "./express-sync-handler"
|
|
4
|
-
import { createExpressSnapshotHandler } from "./express-snapshot-handler"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for creating an Express router for Zuno.
|
|
8
|
-
*/
|
|
9
|
-
type CreateZunoExpressOptions = {
|
|
10
|
-
headers?: IncomingHttpHeaders
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates an Express router for Zuno.
|
|
15
|
-
*
|
|
16
|
-
* @param opts - Options for creating the Express router.
|
|
17
|
-
* @returns An object containing the SSE, sync, and snapshot handlers
|
|
18
|
-
*/
|
|
19
|
-
export function createZunoExpress(opts?: CreateZunoExpressOptions) {
|
|
20
|
-
const { headers } = opts ?? {}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
/**
|
|
24
|
-
* Handles SSE connections.
|
|
25
|
-
*/
|
|
26
|
-
sse: createExpressSSEHandler(headers),
|
|
27
|
-
/**
|
|
28
|
-
* Handles sync connections.
|
|
29
|
-
*/
|
|
30
|
-
sync: createExpressSyncHandler(),
|
|
31
|
-
/**
|
|
32
|
-
* Handles snapshot connections.
|
|
33
|
-
*/
|
|
34
|
-
snapshot: createExpressSnapshotHandler(),
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from "express"
|
|
2
|
-
import { sendSnapshot } from "@iadev93/zuno/server"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates an Express handler for handling Zuno state events.
|
|
6
|
-
* @returns An Express handler function.
|
|
7
|
-
*/
|
|
8
|
-
export function createExpressSnapshotHandler() {
|
|
9
|
-
return (req: Request, res: Response) => sendSnapshot(req, res)
|
|
10
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from "express"
|
|
2
|
-
import type { IncomingHttpHeaders } from "http";
|
|
3
|
-
|
|
4
|
-
import { createSSEConnection } from "@iadev93/zuno/server";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates an SSE handler for express.
|
|
8
|
-
* @returns An Express handler function.
|
|
9
|
-
*/
|
|
10
|
-
export function createExpressSSEHandler(headers?: IncomingHttpHeaders) {
|
|
11
|
-
/**
|
|
12
|
-
* Creates an SSE connection for the client.
|
|
13
|
-
*/
|
|
14
|
-
return (req: Request, res: Response) => createSSEConnection(req, res, headers ?? {})
|
|
15
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from "express"
|
|
2
|
-
import type { ZunoStateEvent } from "@iadev93/zuno"
|
|
3
|
-
|
|
4
|
-
import { applyStateEvent } from "@iadev93/zuno/server"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates an Express handler for handling Zuno state events.
|
|
8
|
-
* @returns An Express handler function.
|
|
9
|
-
*/
|
|
10
|
-
export function createExpressSyncHandler() {
|
|
11
|
-
return (req: Request, res: Response) => {
|
|
12
|
-
/** The incoming state event to apply. */
|
|
13
|
-
const incoming = req.body as ZunoStateEvent
|
|
14
|
-
|
|
15
|
-
/** Applies the incoming state event to the target Zuno universe or store. */
|
|
16
|
-
const result = applyStateEvent(incoming)
|
|
17
|
-
|
|
18
|
-
/** If the state event is not valid, returns a 409 status code with the reason and current state. */
|
|
19
|
-
if (!result.ok) {
|
|
20
|
-
res.status(409).json({
|
|
21
|
-
reason: result.reason,
|
|
22
|
-
current: result.current,
|
|
23
|
-
})
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Returns a 200 status code with the result. */
|
|
28
|
-
res.status(200).json({ ok: true, event: result.event })
|
|
29
|
-
}
|
|
30
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"emitDeclarationOnly": false,
|
|
9
|
-
"module": "ESNext",
|
|
10
|
-
"moduleResolution": "Bundler"
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"./src/**/*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
File without changes
|