@jini-ai/capability-providers 0.6.15 → 0.6.16
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/adapters/ws/index.d.ts +1 -13
- package/dist/adapters/ws/index.js +9 -2
- package/package.json +16 -11
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* `@jini-ai/capability-providers/adapters/ws` — the one real, production-quality
|
|
3
|
-
* `RealtimeProvider` adapter this package ships, using WebSockets (the `ws`
|
|
4
|
-
* package): a self-contained pub/sub server, no external hosted-realtime-service
|
|
5
|
-
* dependency (no Pusher/Ably/Supabase Realtime).
|
|
6
|
-
*
|
|
7
|
-
* Lives at this separate entry point (not the package's main
|
|
8
|
-
* `@jini-ai/capability-providers` barrel) so importing the port
|
|
9
|
-
* interface/types/DI tokens never forces a consumer — or a bundler that
|
|
10
|
-
* can't resolve Node-only packages — to also resolve `ws`. Import from here
|
|
11
|
-
* only when you actually want this concrete adapter.
|
|
12
|
-
*/
|
|
13
|
-
import { WebSocketServer, type ServerOptions } from 'ws';
|
|
1
|
+
import type { WebSocketServer, ServerOptions } from 'ws';
|
|
14
2
|
import type { RealtimeHandler, RealtimeProvider, RealtimeUnsubscribe } from '../../realtime.js';
|
|
15
3
|
/**
|
|
16
4
|
* The minimal structural subset of a `ws` `WebSocket` connection this adapter depends on. A native socket is adapted by the factory; tests construct a plain fake
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* can't resolve Node-only packages — to also resolve `ws`. Import from here
|
|
11
11
|
* only when you actually want this concrete adapter.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { loadOptionalPeer } from '@jini-ai/core/optional-peer';
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
14
16
|
/** WebSocket `readyState` value meaning "open and ready to communicate" (WHATWG WebSocket spec; `ws`'s `WebSocket.OPEN` is the same constant `1`). Spelled out locally so `WebSocketRealtimeProvider`'s core class has no runtime import of `ws` — only the `RealtimeWebSocketLike`/`RealtimeWebSocketServerLike` structural types below, and the `createWebSocketRealtimeProvider` factory, actually touch the real package. */
|
|
15
17
|
const WEBSOCKET_OPEN_STATE = 1;
|
|
16
18
|
/** Parses one inbound client message. Returns `null` for anything not shaped like `{type: 'subscribe'|'unsubscribe', channel: string}` — malformed/unrecognized messages are silently ignored rather than closing the connection, matching a pub/sub transport's normal tolerance for unknown message shapes (e.g. a future protocol version). */
|
|
@@ -134,7 +136,7 @@ export class WebSocketRealtimeProvider {
|
|
|
134
136
|
}
|
|
135
137
|
/** The optional createServer port injects server construction; native ws is the default adapter. The real, production entry point: constructs an actual `ws.WebSocketServer` and wires a `WebSocketRealtimeProvider` to it. Callers that want to inject a fake server for tests should construct `WebSocketRealtimeProvider` directly instead. */
|
|
136
138
|
export function createWebSocketRealtimeProvider(options, optional = {}) {
|
|
137
|
-
const server = (optional.createServer ??
|
|
139
|
+
const server = (optional.createServer ?? createNativeServer)({ wsOptions: options.wsOptions });
|
|
138
140
|
const provider = new WebSocketRealtimeProvider({
|
|
139
141
|
server: {
|
|
140
142
|
on({ listener }) {
|
|
@@ -144,6 +146,11 @@ export function createWebSocketRealtimeProvider(options, optional = {}) {
|
|
|
144
146
|
});
|
|
145
147
|
return { provider, server };
|
|
146
148
|
}
|
|
149
|
+
/** Preserve synchronous construction and let host-injected servers work without the ws peer. */
|
|
150
|
+
function createNativeServer({ wsOptions }) {
|
|
151
|
+
const { WebSocketServer } = loadOptionalPeer({ feature: 'WebSocket realtime adapter', dependency: 'ws', load: () => require('ws') });
|
|
152
|
+
return new WebSocketServer(wsOptions);
|
|
153
|
+
}
|
|
147
154
|
function adaptWebSocket(socket) {
|
|
148
155
|
return {
|
|
149
156
|
get readyState() { return socket.readyState; },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/capability-providers",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"description": "Swappable capability-provider ports (auth, storage, payments, db, realtime) as interfaces and DI tokens only; concrete adapters live behind ./adapters/* subpaths.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"./adapters/blob-storage": "storage",
|
|
30
30
|
"./adapters/jwt-auth": "auth"
|
|
31
31
|
}
|
|
32
|
+
},
|
|
33
|
+
"optionalPeers": {
|
|
34
|
+
"better-sqlite3": "opt-in: sqlite storage — SQLite storage could not load better-sqlite3. Install better-sqlite3 to enable this feature, or check its installed version and native binaries.",
|
|
35
|
+
"ws": "opt-in: websocket realtime adapter; import @jini-ai/capability-providers/adapters/ws — WebSocket realtime adapter could not load ws. Install ws to enable this feature, or check its installed version and native binaries.",
|
|
36
|
+
"@jini-ai/platform": "opt-in: platform-backed adapters; import @jini-ai/capability-providers/adapters/blob-storage — Platform-backed adapters could not load @jini-ai/platform. Install @jini-ai/platform to enable this feature, or check its installed version and native binaries."
|
|
32
37
|
}
|
|
33
38
|
},
|
|
34
39
|
"type": "module",
|
|
@@ -94,13 +99,22 @@
|
|
|
94
99
|
"registry": "https://registry.npmjs.org"
|
|
95
100
|
},
|
|
96
101
|
"dependencies": {
|
|
97
|
-
"@jini-ai/core": "^0.6.
|
|
102
|
+
"@jini-ai/core": "^0.6.16"
|
|
98
103
|
},
|
|
99
104
|
"peerDependencies": {
|
|
100
105
|
"better-sqlite3": "^13.0.0",
|
|
101
106
|
"ws": "^8.18.0",
|
|
102
107
|
"@jini-ai/platform": "^0.6.10"
|
|
103
108
|
},
|
|
109
|
+
"devDependencies": {
|
|
110
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
111
|
+
"@types/ws": "^8.18.0",
|
|
112
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
113
|
+
"better-sqlite3": "^13.0.0",
|
|
114
|
+
"ws": "^8.18.0",
|
|
115
|
+
"@jini-ai/core": "0.6.16",
|
|
116
|
+
"@jini-ai/platform": "0.6.16"
|
|
117
|
+
},
|
|
104
118
|
"peerDependenciesMeta": {
|
|
105
119
|
"better-sqlite3": {
|
|
106
120
|
"optional": true
|
|
@@ -112,15 +126,6 @@
|
|
|
112
126
|
"optional": true
|
|
113
127
|
}
|
|
114
128
|
},
|
|
115
|
-
"devDependencies": {
|
|
116
|
-
"@types/better-sqlite3": "^7.6.11",
|
|
117
|
-
"@types/ws": "^8.18.0",
|
|
118
|
-
"@vitest/coverage-v8": "^2.1.9",
|
|
119
|
-
"better-sqlite3": "^13.0.0",
|
|
120
|
-
"ws": "^8.18.0",
|
|
121
|
-
"@jini-ai/platform": "0.6.15",
|
|
122
|
-
"@jini-ai/core": "0.6.15"
|
|
123
|
-
},
|
|
124
129
|
"scripts": {
|
|
125
130
|
"build": "tsc -p tsconfig.json",
|
|
126
131
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|