@carno.js/live 1.8.0
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 +21 -0
- package/dist/LiveEngine.d.ts +89 -0
- package/dist/LiveEngine.js +520 -0
- package/dist/LivePlugin.d.ts +55 -0
- package/dist/LivePlugin.js +165 -0
- package/dist/LiveService.d.ts +32 -0
- package/dist/LiveService.js +51 -0
- package/dist/auth/authorizer.d.ts +33 -0
- package/dist/auth/authorizer.js +32 -0
- package/dist/bus/InProcessBus.d.ts +8 -0
- package/dist/bus/InProcessBus.js +29 -0
- package/dist/bus/InvalidationBus.d.ts +15 -0
- package/dist/bus/InvalidationBus.js +2 -0
- package/dist/bus/PgNotifyBus.d.ts +55 -0
- package/dist/bus/PgNotifyBus.js +138 -0
- package/dist/client/angular.d.ts +19 -0
- package/dist/client/angular.js +71 -0
- package/dist/client/core.d.ts +111 -0
- package/dist/client/core.js +337 -0
- package/dist/client/hydrate.d.ts +19 -0
- package/dist/client/hydrate.js +65 -0
- package/dist/client/optimistic.d.ts +17 -0
- package/dist/client/optimistic.js +2 -0
- package/dist/client/react.d.ts +22 -0
- package/dist/client/react.js +69 -0
- package/dist/client/transport.d.ts +133 -0
- package/dist/client/transport.js +431 -0
- package/dist/client/vanilla.d.ts +54 -0
- package/dist/client/vanilla.js +111 -0
- package/dist/client/vue.d.ts +12 -0
- package/dist/client/vue.js +35 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.js +21 -0
- package/dist/decorators/Live.d.ts +4 -0
- package/dist/decorators/Live.js +17 -0
- package/dist/emitters/AppEmitter.d.ts +20 -0
- package/dist/emitters/AppEmitter.js +59 -0
- package/dist/emitters/pg-listener.d.ts +50 -0
- package/dist/emitters/pg-listener.js +120 -0
- package/dist/emitters/pg-notify-emitter.d.ts +59 -0
- package/dist/emitters/pg-notify-emitter.js +105 -0
- package/dist/emitters/pg-trigger-sql.d.ts +27 -0
- package/dist/emitters/pg-trigger-sql.js +107 -0
- package/dist/emitters/statement-keys.d.ts +16 -0
- package/dist/emitters/statement-keys.js +182 -0
- package/dist/graph/DependencyGraph.d.ts +27 -0
- package/dist/graph/DependencyGraph.js +118 -0
- package/dist/graph/SubscriptionRegistry.d.ts +22 -0
- package/dist/graph/SubscriptionRegistry.js +92 -0
- package/dist/graph/dep-key.d.ts +14 -0
- package/dist/graph/dep-key.js +37 -0
- package/dist/graph/types.d.ts +13 -0
- package/dist/graph/types.js +2 -0
- package/dist/http/etag.d.ts +41 -0
- package/dist/http/etag.js +109 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +111 -0
- package/dist/metadata.d.ts +16 -0
- package/dist/metadata.js +4 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +44 -0
- package/dist/patch/PatchEngine.d.ts +20 -0
- package/dist/patch/PatchEngine.js +180 -0
- package/dist/patch/types.d.ts +33 -0
- package/dist/patch/types.js +2 -0
- package/dist/resource/ResourceRegistry.d.ts +32 -0
- package/dist/resource/ResourceRegistry.js +126 -0
- package/dist/resource/dependency-context.d.ts +25 -0
- package/dist/resource/dependency-context.js +45 -0
- package/dist/resource/instance-id.d.ts +17 -0
- package/dist/resource/instance-id.js +61 -0
- package/dist/resource/prefetch.d.ts +20 -0
- package/dist/resource/prefetch.js +31 -0
- package/dist/resource/route-executor.d.ts +13 -0
- package/dist/resource/route-executor.js +86 -0
- package/dist/resource/types.d.ts +26 -0
- package/dist/resource/types.js +2 -0
- package/dist/runtime.d.ts +41 -0
- package/dist/runtime.js +47 -0
- package/dist/shared/canonical.d.ts +14 -0
- package/dist/shared/canonical.js +60 -0
- package/dist/shared/descriptor.d.ts +44 -0
- package/dist/shared/descriptor.js +19 -0
- package/dist/shared/hash.d.ts +12 -0
- package/dist/shared/hash.js +29 -0
- package/dist/shared/inputs.d.ts +19 -0
- package/dist/shared/inputs.js +2 -0
- package/dist/shared/protocol.d.ts +83 -0
- package/dist/shared/protocol.js +9 -0
- package/dist/transport/FanTransport.d.ts +18 -0
- package/dist/transport/FanTransport.js +29 -0
- package/dist/transport/LiveGateway.d.ts +16 -0
- package/dist/transport/LiveGateway.js +126 -0
- package/dist/transport/SocketTransport.d.ts +18 -0
- package/dist/transport/SocketTransport.js +40 -0
- package/dist/transport/SseTransport.d.ts +30 -0
- package/dist/transport/SseTransport.js +92 -0
- package/dist/transport/scope-resolver.d.ts +20 -0
- package/dist/transport/scope-resolver.js +17 -0
- package/dist/transport/sse-routes.d.ts +24 -0
- package/dist/transport/sse-routes.js +78 -0
- package/package.json +92 -0
- package/src/LiveEngine.ts +730 -0
- package/src/LivePlugin.ts +253 -0
- package/src/LiveService.ts +47 -0
- package/src/auth/authorizer.ts +56 -0
- package/src/bus/InProcessBus.ts +28 -0
- package/src/bus/InvalidationBus.ts +17 -0
- package/src/bus/PgNotifyBus.ts +188 -0
- package/src/client/angular.ts +115 -0
- package/src/client/core.ts +492 -0
- package/src/client/hydrate.ts +80 -0
- package/src/client/optimistic.ts +19 -0
- package/src/client/react.ts +113 -0
- package/src/client/transport.ts +568 -0
- package/src/client/vanilla.ts +165 -0
- package/src/client/vue.ts +67 -0
- package/src/config.ts +49 -0
- package/src/decorators/Live.ts +16 -0
- package/src/emitters/AppEmitter.ts +69 -0
- package/src/emitters/pg-listener.ts +171 -0
- package/src/emitters/pg-notify-emitter.ts +143 -0
- package/src/emitters/pg-trigger-sql.ts +111 -0
- package/src/emitters/statement-keys.ts +229 -0
- package/src/graph/DependencyGraph.ts +147 -0
- package/src/graph/SubscriptionRegistry.ts +109 -0
- package/src/graph/dep-key.ts +41 -0
- package/src/graph/types.ts +15 -0
- package/src/http/etag.ts +144 -0
- package/src/index.ts +81 -0
- package/src/metadata.ts +21 -0
- package/src/observability.ts +54 -0
- package/src/patch/PatchEngine.ts +235 -0
- package/src/patch/types.ts +39 -0
- package/src/resource/ResourceRegistry.ts +178 -0
- package/src/resource/dependency-context.ts +48 -0
- package/src/resource/instance-id.ts +65 -0
- package/src/resource/prefetch.ts +49 -0
- package/src/resource/route-executor.ts +134 -0
- package/src/resource/types.ts +35 -0
- package/src/runtime.ts +69 -0
- package/src/shared/canonical.ts +63 -0
- package/src/shared/descriptor.ts +44 -0
- package/src/shared/hash.ts +31 -0
- package/src/shared/inputs.ts +20 -0
- package/src/shared/protocol.ts +96 -0
- package/src/transport/FanTransport.ts +34 -0
- package/src/transport/LiveGateway.ts +124 -0
- package/src/transport/SocketTransport.ts +43 -0
- package/src/transport/SseTransport.ts +112 -0
- package/src/transport/scope-resolver.ts +25 -0
- package/src/transport/sse-routes.ts +94 -0
- package/test/acceptance-fase-2.test.ts +248 -0
- package/test/acceptance-fase-3.test.ts +216 -0
- package/test/acceptance.test.ts +306 -0
- package/test/angular-adapter.test.ts +151 -0
- package/test/app-emitter.test.ts +112 -0
- package/test/authorization.test.ts +175 -0
- package/test/client-core.test.ts +287 -0
- package/test/client-transport.test.ts +154 -0
- package/test/dependency-graph.test.ts +83 -0
- package/test/etag.test.ts +193 -0
- package/test/fan-transport.test.ts +62 -0
- package/test/happydom.ts +24 -0
- package/test/inputs-body.test.ts +81 -0
- package/test/instance-id.test.ts +104 -0
- package/test/live-engine.test.ts +593 -0
- package/test/live-post.test.ts +81 -0
- package/test/metrics.test.ts +131 -0
- package/test/optimistic.test.ts +166 -0
- package/test/orm-integration.test.ts +75 -0
- package/test/patch-engine.test.ts +121 -0
- package/test/pg-bus.test.ts +162 -0
- package/test/pg-listen-probe.test.ts +56 -0
- package/test/pg-listener.test.ts +134 -0
- package/test/pg-notify-emitter.test.ts +113 -0
- package/test/pg-notify-integration.test.ts +88 -0
- package/test/polling-auth.test.ts +169 -0
- package/test/prefetch.test.ts +137 -0
- package/test/react-adapter.test.tsx +83 -0
- package/test/react-rerender.test.tsx +131 -0
- package/test/resource-registry-helper.ts +35 -0
- package/test/resource-registry.test.ts +144 -0
- package/test/route-pipeline.test.ts +139 -0
- package/test/shared.test.ts +53 -0
- package/test/sse-routes.test.ts +204 -0
- package/test/sse-transport.test.ts +91 -0
- package/test/statement-keys.test.ts +126 -0
- package/test/subscription-registry.test.ts +61 -0
- package/test/transport-ladder.test.ts +293 -0
- package/test/transport.test.ts +274 -0
- package/test/types/optimistic-types.ts +34 -0
- package/test/use-live-action.test.ts +127 -0
- package/test/use-live.test.ts +109 -0
- package/test/vanilla-adapter.test.ts +200 -0
- package/test/vue-adapter.test.ts +122 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +10 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSseRoutes = createSseRoutes;
|
|
4
|
+
const runtime_1 = require("../runtime");
|
|
5
|
+
const LiveGateway_1 = require("./LiveGateway");
|
|
6
|
+
// Captured at load so a later happy-dom register cannot replace the
|
|
7
|
+
// constructor Bun.serve requires of a route handler.
|
|
8
|
+
const NativeResponse = Response;
|
|
9
|
+
const SSE_HEADERS = {
|
|
10
|
+
'Content-Type': 'text/event-stream',
|
|
11
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
12
|
+
Connection: 'keep-alive',
|
|
13
|
+
// Nginx buffers proxied responses by default, which turns a live stream
|
|
14
|
+
// into a stream that arrives all at once, at the end.
|
|
15
|
+
'X-Accel-Buffering': 'no'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The two halves of the SSE transport, as HTTP.
|
|
19
|
+
*
|
|
20
|
+
* `GET streamPath` opens the downstream and names the connection; every
|
|
21
|
+
* client message goes up through `POST controlPath` and into the same
|
|
22
|
+
* `handleMessage` the WebSocket gateway uses. There is no second protocol
|
|
23
|
+
* here, and there must never be one.
|
|
24
|
+
*
|
|
25
|
+
* Handlers registered through `Carno.route()` receive a Bun `Request`, not a
|
|
26
|
+
* `Context` -- the docstring on that method says otherwise, the runtime does
|
|
27
|
+
* not.
|
|
28
|
+
*/
|
|
29
|
+
function createSseRoutes(options) {
|
|
30
|
+
const { transport, streamPath, controlPath } = options;
|
|
31
|
+
const stream = (request) => {
|
|
32
|
+
// Unguessable on purpose: the id is a bearer for this connection, and
|
|
33
|
+
// whoever holds it can subscribe as it.
|
|
34
|
+
const connectionId = `sse:${crypto.randomUUID()}`;
|
|
35
|
+
try {
|
|
36
|
+
const body = transport.open(connectionId);
|
|
37
|
+
const runtime = (0, runtime_1.getLiveRuntime)();
|
|
38
|
+
// Until a `hello` arrives, the connection is its own principal:
|
|
39
|
+
// safe, shares nothing. Same rule as the gateway's onOpen.
|
|
40
|
+
runtime.scopes.set(connectionId, { principal: connectionId });
|
|
41
|
+
runtime.handshakes.delete(connectionId);
|
|
42
|
+
// Cancelling the client reader does not always reach the stream's
|
|
43
|
+
// `cancel`; aborting the request does, and is what a closed
|
|
44
|
+
// EventSource looks like on the wire.
|
|
45
|
+
request.signal.addEventListener('abort', () => {
|
|
46
|
+
transport.close(connectionId);
|
|
47
|
+
try {
|
|
48
|
+
(0, LiveGateway_1.dropLiveConnection)(connectionId);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// closeLiveRuntime nulls the runtime before dispose.
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return new NativeResponse(body, { status: 200, headers: SSE_HEADERS });
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return new NativeResponse(error.message, { status: 503 });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const control = async (request) => {
|
|
61
|
+
let payload;
|
|
62
|
+
try {
|
|
63
|
+
payload = await request.json();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return new NativeResponse('malformed body', { status: 400 });
|
|
67
|
+
}
|
|
68
|
+
if (typeof payload.cid !== 'string' || !payload.message) {
|
|
69
|
+
return new NativeResponse('cid and message are required', { status: 400 });
|
|
70
|
+
}
|
|
71
|
+
if (!transport.owns(payload.cid)) {
|
|
72
|
+
return new NativeResponse('unknown connection', { status: 404 });
|
|
73
|
+
}
|
|
74
|
+
await (0, LiveGateway_1.handleMessage)(payload.cid, JSON.stringify(payload.message));
|
|
75
|
+
return new NativeResponse(null, { status: 204 });
|
|
76
|
+
};
|
|
77
|
+
return { streamPath, controlPath, stream, control };
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@carno.js/live",
|
|
3
|
+
"version": "1.8.0",
|
|
4
|
+
"description": "Server-owned reactive state for Carno.js: live resources, dependency-graph invalidation, and framework-native client stores",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client/core.d.ts",
|
|
17
|
+
"require": "./dist/client/core.js",
|
|
18
|
+
"default": "./dist/client/core.js"
|
|
19
|
+
},
|
|
20
|
+
"./react": {
|
|
21
|
+
"types": "./dist/client/react.d.ts",
|
|
22
|
+
"require": "./dist/client/react.js",
|
|
23
|
+
"default": "./dist/client/react.js"
|
|
24
|
+
},
|
|
25
|
+
"./vanilla": {
|
|
26
|
+
"types": "./dist/client/vanilla.d.ts",
|
|
27
|
+
"require": "./dist/client/vanilla.js",
|
|
28
|
+
"default": "./dist/client/vanilla.js"
|
|
29
|
+
},
|
|
30
|
+
"./angular": {
|
|
31
|
+
"types": "./dist/client/angular.d.ts",
|
|
32
|
+
"require": "./dist/client/angular.js",
|
|
33
|
+
"default": "./dist/client/angular.js"
|
|
34
|
+
},
|
|
35
|
+
"./vue": {
|
|
36
|
+
"types": "./dist/client/vue.d.ts",
|
|
37
|
+
"require": "./dist/client/vue.js",
|
|
38
|
+
"default": "./dist/client/vue.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"compile": "rm -rf ./dist tsconfig.tsbuildinfo && tsc --build --force",
|
|
43
|
+
"build": "tsc --build --force",
|
|
44
|
+
"test": "bun test",
|
|
45
|
+
"prepublishOnly": "bun run build"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@angular/core": ">=18.0.0",
|
|
49
|
+
"@carno.js/core": "^1.7.0",
|
|
50
|
+
"@carno.js/orm": "^1.7.0",
|
|
51
|
+
"@carno.js/websocket": "^1.7.0",
|
|
52
|
+
"react": ">=18.0.0",
|
|
53
|
+
"vue": ">=3.4.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@carno.js/orm": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"react": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"@angular/core": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"vue": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@angular/core": "^18.2.0",
|
|
71
|
+
"@happy-dom/global-registrator": "^20.0.0",
|
|
72
|
+
"@testing-library/dom": "^10.4.0",
|
|
73
|
+
"@testing-library/react": "^16.1.0",
|
|
74
|
+
"@types/react": "^18.3.12",
|
|
75
|
+
"react": "^18.3.1",
|
|
76
|
+
"react-dom": "^18.3.1",
|
|
77
|
+
"vue": "^3.5.0"
|
|
78
|
+
},
|
|
79
|
+
"keywords": [
|
|
80
|
+
"carno",
|
|
81
|
+
"carno.js",
|
|
82
|
+
"live",
|
|
83
|
+
"realtime",
|
|
84
|
+
"reactive",
|
|
85
|
+
"websocket"
|
|
86
|
+
],
|
|
87
|
+
"license": "MIT",
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
},
|
|
91
|
+
"gitHead": "4eacc5852543c296787a2f8b92795a1775de44fa"
|
|
92
|
+
}
|