@arcote.tech/arc-host 0.7.14 → 0.7.15
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/index.js +131 -157
- package/dist/index.js.map +5 -5
- package/dist/src/create-server.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/middleware/http.d.ts +0 -5
- package/dist/src/middleware/http.d.ts.map +1 -1
- package/dist/src/middleware/index.d.ts +2 -2
- package/dist/src/middleware/index.d.ts.map +1 -1
- package/dist/src/middleware/view-subscription.integration.test.d.ts +2 -0
- package/dist/src/middleware/view-subscription.integration.test.d.ts.map +1 -0
- package/dist/src/middleware/ws.d.ts +30 -1
- package/dist/src/middleware/ws.d.ts.map +1 -1
- package/dist/src/middleware/ws.test.d.ts +2 -0
- package/dist/src/middleware/ws.test.d.ts.map +1 -0
- package/dist/src/types.d.ts +29 -13
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/create-server.ts +8 -2
- package/src/index.ts +2 -3
- package/src/middleware/http.ts +0 -119
- package/src/middleware/index.ts +2 -3
- package/src/middleware/view-subscription.integration.test.ts +307 -0
- package/src/middleware/ws.test.ts +95 -0
- package/src/middleware/ws.ts +203 -77
- package/src/types.ts +25 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../../src/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAQ,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAA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E,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOjD,OAAO,KAAK,EACV,cAAc,EAGd,YAAY,EACb,MAAM,oBAAoB,CAAC;AAG5B,KAAK,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACzD,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;kEAG8D;IAC9D,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,SAAS,CAAC,CAgQpB"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createArcServer } from "./create-server";
|
|
2
2
|
export type { ArcServer, ArcServerConfig } from "./create-server";
|
|
3
|
-
export { arcHttpHandlers, arcWsHandlers,
|
|
3
|
+
export { arcHttpHandlers, arcWsHandlers, broadcastViewChanges, cleanupClientSubs, commandHandler, eventSyncHandler, executeCommandHandler, healthHandler, queryHandler, requestSyncHandler, routeHandler, scopeAuthHandler, syncEventsHandler, viewSubscriptionHandler, } from "./middleware";
|
|
4
4
|
export type { ArcHttpHandler, ArcRequestContext, ArcWsContext, ArcWsHandler, } from "./middleware";
|
|
5
5
|
export { ConnectionManager } from "./connection-manager";
|
|
6
6
|
export { ContextHandler } from "./context-handler";
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,YAAY,GACb,MAAM,SAAS,CAAC"}
|
|
@@ -4,12 +4,7 @@ import type { ArcHttpHandler } from "./types";
|
|
|
4
4
|
export declare function healthHandler(cm: ConnectionManager): ArcHttpHandler;
|
|
5
5
|
export declare function commandHandler(ch: ContextHandler): ArcHttpHandler;
|
|
6
6
|
export declare function queryHandler(ch: ContextHandler): ArcHttpHandler;
|
|
7
|
-
export declare function streamHandler(ch: ContextHandler): ArcHttpHandler;
|
|
8
7
|
export declare function eventSyncHandler(ch: ContextHandler): ArcHttpHandler;
|
|
9
8
|
export declare function routeHandler(ch: ContextHandler): ArcHttpHandler;
|
|
10
9
|
export declare function arcHttpHandlers(ch: ContextHandler, cm: ConnectionManager): ArcHttpHandler[];
|
|
11
|
-
/**
|
|
12
|
-
* Cleanup all active SSE stream connections.
|
|
13
|
-
*/
|
|
14
|
-
export declare function cleanupStreams(): void;
|
|
15
10
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/middleware/http.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,SAAS,CAAC;AAoCjE,wBAAgB,aAAa,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc,CAQnE;AAMD,wBAAgB,cAAc,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CA+BjE;AAMD,wBAAgB,YAAY,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CAoC/D;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/middleware/http.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,SAAS,CAAC;AAoCjE,wBAAgB,aAAa,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc,CAQnE;AAMD,wBAAgB,cAAc,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CA+BjE;AAMD,wBAAgB,YAAY,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CAoC/D;AAMD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CA4BnE;AAMD,wBAAgB,YAAY,CAAC,EAAE,EAAE,cAAc,GAAG,cAAc,CA8G/D;AAMD,wBAAgB,eAAe,CAC7B,EAAE,EAAE,cAAc,EAClB,EAAE,EAAE,iBAAiB,GACpB,cAAc,EAAE,CAQlB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { ArcHttpHandler, ArcRequestContext, ArcWsContext, ArcWsHandler, } from "./types";
|
|
2
|
-
export { arcHttpHandlers,
|
|
3
|
-
export { arcWsHandlers, cleanupClientSubs, executeCommandHandler, requestSyncHandler, scopeAuthHandler, syncEventsHandler,
|
|
2
|
+
export { arcHttpHandlers, commandHandler, eventSyncHandler, healthHandler, queryHandler, routeHandler, } from "./http";
|
|
3
|
+
export { arcWsHandlers, broadcastViewChanges, cleanupClientSubs, executeCommandHandler, requestSyncHandler, scopeAuthHandler, syncEventsHandler, viewSubscriptionHandler, } from "./ws";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,eAAe,EACf,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-subscription.integration.test.d.ts","sourceRoot":"","sources":["../../../src/middleware/view-subscription.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,38 @@
|
|
|
1
|
+
import { type CommittedChange } from "@arcote.tech/arc";
|
|
2
|
+
import type { ConnectionManager } from "../connection-manager";
|
|
1
3
|
import type { ArcWsHandler } from "./types";
|
|
4
|
+
type WireViewChange = {
|
|
5
|
+
type: "set";
|
|
6
|
+
id: string;
|
|
7
|
+
item: any;
|
|
8
|
+
} | {
|
|
9
|
+
type: "delete";
|
|
10
|
+
id: string;
|
|
11
|
+
item: null;
|
|
12
|
+
};
|
|
2
13
|
export declare function cleanupClientSubs(clientId: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Filter a committed change for one subscriber:
|
|
16
|
+
* - new row matches → `set` with the full row
|
|
17
|
+
* - only old row matched → `delete` (item left the subscriber's slice)
|
|
18
|
+
* - neither → nothing (not in this tenant's slice; no id leakage)
|
|
19
|
+
*/
|
|
20
|
+
export declare function filterChangeForSubscriber(change: CommittedChange, restrictions: Record<string, unknown> | null): WireViewChange | null;
|
|
21
|
+
/**
|
|
22
|
+
* Broadcast committed view deltas to subscribed clients. Wired to
|
|
23
|
+
* `LocalEventPublisher.onViewChanges` in create-server — fires after each
|
|
24
|
+
* successful publish commit, regardless of the event's origin
|
|
25
|
+
* (execute-command, client sync-events, server-side listeners).
|
|
26
|
+
*
|
|
27
|
+
* One `view-changes` message per (commit × view × client); empty results
|
|
28
|
+
* are skipped entirely.
|
|
29
|
+
*/
|
|
30
|
+
export declare function broadcastViewChanges(committed: CommittedChange[], connectionManager: ConnectionManager): void;
|
|
3
31
|
export declare function scopeAuthHandler(): ArcWsHandler;
|
|
4
32
|
export declare function syncEventsHandler(): ArcWsHandler;
|
|
5
33
|
export declare function requestSyncHandler(): ArcWsHandler;
|
|
6
34
|
export declare function executeCommandHandler(): ArcWsHandler;
|
|
7
|
-
export declare function
|
|
35
|
+
export declare function viewSubscriptionHandler(): ArcWsHandler;
|
|
8
36
|
export declare function arcWsHandlers(): ArcWsHandler[];
|
|
37
|
+
export {};
|
|
9
38
|
//# sourceMappingURL=ws.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../../src/middleware/ws.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../../src/middleware/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,SAAS,CAAC;AAY1D,KAAK,cAAc,GACf;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAa/C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOxD;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,eAAe,EACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAC3C,cAAc,GAAG,IAAI,CAcvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,eAAe,EAAE,EAC5B,iBAAiB,EAAE,iBAAiB,GACnC,IAAI,CAsCN;AAMD,wBAAgB,gBAAgB,IAAI,YAAY,CAc/C;AAMD,wBAAgB,iBAAiB,IAAI,YAAY,CA4ChD;AAMD,wBAAgB,kBAAkB,IAAI,YAAY,CAmCjD;AAMD,wBAAgB,qBAAqB,IAAI,YAAY,CA6BpD;AAMD,wBAAgB,uBAAuB,IAAI,YAAY,CA0GtD;AAMD,wBAAgB,aAAa,IAAI,YAAY,EAAE,CAQ9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.test.d.ts","sourceRoot":"","sources":["../../../src/middleware/ws.test.ts"],"names":[],"mappings":""}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export interface ConnectedClient {
|
|
|
42
42
|
lastHostEventId: string | null;
|
|
43
43
|
/** WebSocket instance */
|
|
44
44
|
ws: any;
|
|
45
|
+
/**
|
|
46
|
+
* True for local-mode clients (they sent request-sync / sync-events).
|
|
47
|
+
* Only these receive domain-event broadcasts — streaming clients are
|
|
48
|
+
* served by view snapshots + deltas instead.
|
|
49
|
+
*/
|
|
50
|
+
wantsEventSync?: boolean;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* Auth context snapshot captured at event emission time.
|
|
@@ -96,17 +102,13 @@ export type ClientToHostMessage = {
|
|
|
96
102
|
scope: string;
|
|
97
103
|
token: string;
|
|
98
104
|
} | {
|
|
99
|
-
type: "subscribe-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
element: string;
|
|
103
|
-
method: string;
|
|
104
|
-
args: any[];
|
|
105
|
-
};
|
|
106
|
-
scope?: string;
|
|
105
|
+
type: "subscribe-view";
|
|
106
|
+
element: string;
|
|
107
|
+
scope: string;
|
|
107
108
|
} | {
|
|
108
|
-
type: "unsubscribe-
|
|
109
|
-
|
|
109
|
+
type: "unsubscribe-view";
|
|
110
|
+
element: string;
|
|
111
|
+
scope: string;
|
|
110
112
|
};
|
|
111
113
|
/**
|
|
112
114
|
* Messages from host to client
|
|
@@ -126,8 +128,22 @@ export type HostToClientMessage = {
|
|
|
126
128
|
type: "error";
|
|
127
129
|
message: string;
|
|
128
130
|
} | {
|
|
129
|
-
type: "
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
type: "view-snapshot";
|
|
132
|
+
element: string;
|
|
133
|
+
scope: string;
|
|
134
|
+
items: any[];
|
|
135
|
+
} | {
|
|
136
|
+
type: "view-changes";
|
|
137
|
+
element: string;
|
|
138
|
+
scope: string;
|
|
139
|
+
changes: Array<{
|
|
140
|
+
type: "set";
|
|
141
|
+
id: string;
|
|
142
|
+
item: any;
|
|
143
|
+
} | {
|
|
144
|
+
type: "delete";
|
|
145
|
+
id: string;
|
|
146
|
+
item: null;
|
|
147
|
+
}>;
|
|
132
148
|
};
|
|
133
149
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,+BAA+B;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IA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AC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,GACtC;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAC7C,CAAC;CACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.7.
|
|
7
|
+
"version": "0.7.15",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@arcote.tech/arc-adapter-db-sqlite": "^0.7.
|
|
11
|
+
"@arcote.tech/arc-adapter-db-sqlite": "^0.7.15",
|
|
12
12
|
"croner": "^9.0.0",
|
|
13
13
|
"jsonwebtoken": "^9.0.2"
|
|
14
14
|
},
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@types/bun": "^1.2.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@arcote.tech/arc": "^0.7.
|
|
28
|
-
"@arcote.tech/arc-otel": "^0.7.
|
|
27
|
+
"@arcote.tech/arc": "^0.7.15",
|
|
28
|
+
"@arcote.tech/arc-otel": "^0.7.15"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
31
31
|
"@arcote.tech/arc-otel": {
|
package/src/create-server.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { CronScheduler } from "./cron-scheduler";
|
|
|
8
8
|
import {
|
|
9
9
|
arcHttpHandlers,
|
|
10
10
|
arcWsHandlers,
|
|
11
|
+
broadcastViewChanges,
|
|
11
12
|
cleanupClientSubs,
|
|
12
|
-
cleanupStreams,
|
|
13
13
|
} from "./middleware";
|
|
14
14
|
import type {
|
|
15
15
|
ArcHttpHandler,
|
|
@@ -84,6 +84,13 @@ export async function createArcServer(
|
|
|
84
84
|
|
|
85
85
|
const connectionManager = new ConnectionManager();
|
|
86
86
|
|
|
87
|
+
// Broadcast committed view deltas to subscribed streaming clients.
|
|
88
|
+
// Fires after every publish commit (execute-command, client sync-events,
|
|
89
|
+
// server-side listeners) — see viewSubscriptionHandler in middleware/ws.
|
|
90
|
+
contextHandler
|
|
91
|
+
.getEventPublisher()
|
|
92
|
+
.onViewChanges((changes) => broadcastViewChanges(changes, connectionManager));
|
|
93
|
+
|
|
87
94
|
function buildCorsHeaders(req?: Request) {
|
|
88
95
|
const origin = req?.headers.get("Origin") || "*";
|
|
89
96
|
return {
|
|
@@ -300,7 +307,6 @@ export async function createArcServer(
|
|
|
300
307
|
cronScheduler,
|
|
301
308
|
stop: () => {
|
|
302
309
|
cronScheduler.stop();
|
|
303
|
-
cleanupStreams();
|
|
304
310
|
server.stop();
|
|
305
311
|
},
|
|
306
312
|
};
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,8 @@ export type { ArcServer, ArcServerConfig } from "./create-server";
|
|
|
6
6
|
export {
|
|
7
7
|
arcHttpHandlers,
|
|
8
8
|
arcWsHandlers,
|
|
9
|
+
broadcastViewChanges,
|
|
9
10
|
cleanupClientSubs,
|
|
10
|
-
cleanupStreams,
|
|
11
11
|
commandHandler,
|
|
12
12
|
eventSyncHandler,
|
|
13
13
|
executeCommandHandler,
|
|
@@ -16,9 +16,8 @@ export {
|
|
|
16
16
|
requestSyncHandler,
|
|
17
17
|
routeHandler,
|
|
18
18
|
scopeAuthHandler,
|
|
19
|
-
streamHandler,
|
|
20
19
|
syncEventsHandler,
|
|
21
|
-
|
|
20
|
+
viewSubscriptionHandler,
|
|
22
21
|
} from "./middleware";
|
|
23
22
|
export type {
|
|
24
23
|
ArcHttpHandler,
|
package/src/middleware/http.ts
CHANGED
|
@@ -127,116 +127,6 @@ export function queryHandler(ch: ContextHandler): ArcHttpHandler {
|
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
// ---------------------------------------------------------------------------
|
|
131
|
-
// Stream — GET /stream/:viewName (SSE)
|
|
132
|
-
// ---------------------------------------------------------------------------
|
|
133
|
-
|
|
134
|
-
interface StreamConnection {
|
|
135
|
-
id: string;
|
|
136
|
-
controller: ReadableStreamDefaultController<Uint8Array>;
|
|
137
|
-
unsubscribe: () => void;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let streamIdCounter = 0;
|
|
141
|
-
const streamConnections = new Map<string, StreamConnection>();
|
|
142
|
-
|
|
143
|
-
export function streamHandler(ch: ContextHandler): ArcHttpHandler {
|
|
144
|
-
return (_req, url, ctx) => {
|
|
145
|
-
if (!url.pathname.startsWith("/stream/") || _req.method !== "GET")
|
|
146
|
-
return null;
|
|
147
|
-
|
|
148
|
-
const viewName = url.pathname.split("/stream/")[1];
|
|
149
|
-
if (!viewName) {
|
|
150
|
-
return new Response("Invalid stream path", {
|
|
151
|
-
status: 400,
|
|
152
|
-
headers: ctx.corsHeaders,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const findOptions: any = {};
|
|
157
|
-
const whereParam = url.searchParams.get("where");
|
|
158
|
-
if (whereParam) {
|
|
159
|
-
try {
|
|
160
|
-
findOptions.where = JSON.parse(whereParam);
|
|
161
|
-
} catch {
|
|
162
|
-
return new Response("Invalid 'where' parameter", {
|
|
163
|
-
status: 400,
|
|
164
|
-
headers: ctx.corsHeaders,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const orderByParam = url.searchParams.get("orderBy");
|
|
169
|
-
if (orderByParam) {
|
|
170
|
-
try {
|
|
171
|
-
findOptions.orderBy = JSON.parse(orderByParam);
|
|
172
|
-
} catch {
|
|
173
|
-
return new Response("Invalid 'orderBy' parameter", {
|
|
174
|
-
status: 400,
|
|
175
|
-
headers: ctx.corsHeaders,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const limitParam = url.searchParams.get("limit");
|
|
180
|
-
if (limitParam) findOptions.limit = parseInt(limitParam, 10);
|
|
181
|
-
|
|
182
|
-
const streamId = `stream_${++streamIdCounter}_${Date.now()}`;
|
|
183
|
-
const rawToken = ctx.rawToken;
|
|
184
|
-
|
|
185
|
-
const stream = new ReadableStream<Uint8Array>({
|
|
186
|
-
start(controller) {
|
|
187
|
-
const scoped = new ScopedModel(ch.getModel(), "stream");
|
|
188
|
-
if (rawToken) scoped.setToken(rawToken);
|
|
189
|
-
|
|
190
|
-
const descriptor = { element: viewName, method: "find", args: [findOptions] };
|
|
191
|
-
|
|
192
|
-
const sendData = async () => {
|
|
193
|
-
try {
|
|
194
|
-
const data = await scoped.callQuery(descriptor);
|
|
195
|
-
controller.enqueue(
|
|
196
|
-
new TextEncoder().encode(
|
|
197
|
-
`data: ${JSON.stringify({ type: "data", data })}\n\n`,
|
|
198
|
-
),
|
|
199
|
-
);
|
|
200
|
-
} catch {
|
|
201
|
-
unsubscribe();
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
// Initial data
|
|
206
|
-
sendData();
|
|
207
|
-
|
|
208
|
-
// Subscribe to changes
|
|
209
|
-
const unsubscribe = ch
|
|
210
|
-
.getEventPublisher()
|
|
211
|
-
.subscribe("*", () => sendData());
|
|
212
|
-
|
|
213
|
-
streamConnections.set(streamId, { id: streamId, controller, unsubscribe });
|
|
214
|
-
controller.enqueue(
|
|
215
|
-
new TextEncoder().encode(
|
|
216
|
-
`data: ${JSON.stringify({ type: "connected", streamId })}\n\n`,
|
|
217
|
-
),
|
|
218
|
-
);
|
|
219
|
-
},
|
|
220
|
-
cancel() {
|
|
221
|
-
const conn = streamConnections.get(streamId);
|
|
222
|
-
if (conn) {
|
|
223
|
-
conn.unsubscribe();
|
|
224
|
-
streamConnections.delete(streamId);
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
return new Response(stream, {
|
|
230
|
-
headers: {
|
|
231
|
-
...ctx.corsHeaders,
|
|
232
|
-
"Content-Type": "text/event-stream",
|
|
233
|
-
"Cache-Control": "no-cache",
|
|
234
|
-
Connection: "keep-alive",
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
130
|
// ---------------------------------------------------------------------------
|
|
241
131
|
// Event Sync — POST /sync/events
|
|
242
132
|
// ---------------------------------------------------------------------------
|
|
@@ -399,16 +289,7 @@ export function arcHttpHandlers(
|
|
|
399
289
|
healthHandler(cm),
|
|
400
290
|
commandHandler(ch),
|
|
401
291
|
queryHandler(ch),
|
|
402
|
-
streamHandler(ch),
|
|
403
292
|
eventSyncHandler(ch),
|
|
404
293
|
routeHandler(ch),
|
|
405
294
|
];
|
|
406
295
|
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Cleanup all active SSE stream connections.
|
|
410
|
-
*/
|
|
411
|
-
export function cleanupStreams(): void {
|
|
412
|
-
for (const conn of streamConnections.values()) conn.unsubscribe();
|
|
413
|
-
streamConnections.clear();
|
|
414
|
-
}
|
package/src/middleware/index.ts
CHANGED
|
@@ -7,21 +7,20 @@ export type {
|
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
arcHttpHandlers,
|
|
10
|
-
cleanupStreams,
|
|
11
10
|
commandHandler,
|
|
12
11
|
eventSyncHandler,
|
|
13
12
|
healthHandler,
|
|
14
13
|
queryHandler,
|
|
15
14
|
routeHandler,
|
|
16
|
-
streamHandler,
|
|
17
15
|
} from "./http";
|
|
18
16
|
|
|
19
17
|
export {
|
|
20
18
|
arcWsHandlers,
|
|
19
|
+
broadcastViewChanges,
|
|
21
20
|
cleanupClientSubs,
|
|
22
21
|
executeCommandHandler,
|
|
23
22
|
requestSyncHandler,
|
|
24
23
|
scopeAuthHandler,
|
|
25
24
|
syncEventsHandler,
|
|
26
|
-
|
|
25
|
+
viewSubscriptionHandler,
|
|
27
26
|
} from "./ws";
|