@atcute/xrpc-server-deno 0.1.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 ADDED
@@ -0,0 +1,14 @@
1
+ BSD Zero Clause License
2
+
3
+ Copyright (c) 2025 Mary
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @atcute/xrpc-server-deno
2
+
3
+ Deno WebSocket adapter for `@atcute/xrpc-server`.
4
+
5
+ ```ts
6
+ import { XRPCRouter } from '@atcute/xrpc-server';
7
+ import { createDenoWebSocket } from '@atcute/xrpc-server-deno';
8
+
9
+ import { ComAtprotoSyncSubscribeRepos } from './lexicons/index.ts';
10
+
11
+ const adapter = createDenoWebSocket();
12
+ const router = new XRPCRouter({ websocket: adapter });
13
+
14
+ router.addSubscription(ComAtprotoSyncSubscribeRepos.mainSchema, {
15
+ async *handler({ params, signal }) {
16
+ while (!signal.aborted) {
17
+ yield {
18
+ // ...
19
+ };
20
+ }
21
+ },
22
+ });
23
+
24
+ export default router satisfies Deno.ServeDefaultExport;
25
+ ```
@@ -0,0 +1,3 @@
1
+ import type { WebSocketAdapter } from '@atcute/xrpc-server';
2
+ export declare const createDenoWebSocket: () => WebSocketAdapter;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAuB,MAAM,qBAAqB,CAAC;AAEjF,eAAO,MAAM,mBAAmB,QAAO,gBA2BtC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ export const createDenoWebSocket = () => {
2
+ return {
3
+ async upgrade(request, handler) {
4
+ const { response, socket } = Deno.upgradeWebSocket(request);
5
+ const controller = new AbortController();
6
+ const connection = {
7
+ signal: controller.signal,
8
+ send(data) {
9
+ socket.send(data);
10
+ },
11
+ close(code, reason) {
12
+ socket.close(code, reason);
13
+ },
14
+ };
15
+ socket.onopen = () => {
16
+ handler(connection);
17
+ };
18
+ socket.onclose = (ev) => {
19
+ controller.abort(`WebSocket connection closed with code ${ev.code}`);
20
+ };
21
+ return response;
22
+ },
23
+ };
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAqB,EAAE;IACzD,OAAO;QACN,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO;YAC7B,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAE5D,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,UAAU,GAAwB;gBACvC,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,IAAI,CAAC,IAAgB;oBACpB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnB,CAAC;gBACD,KAAK,CAAC,IAAa,EAAE,MAAe;oBACnC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC5B,CAAC;aACD,CAAC;YAEF,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;gBACpB,OAAO,CAAC,UAAU,CAAC,CAAC;YACrB,CAAC,CAAC;YAEF,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,EAAE,EAAE;gBACvB,UAAU,CAAC,KAAK,CAAC,yCAAyC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC;YAEF,OAAO,QAAQ,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC,CAAC"}
package/lib/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { WebSocketAdapter, WebSocketConnection } from '@atcute/xrpc-server';
2
+
3
+ export const createDenoWebSocket = (): WebSocketAdapter => {
4
+ return {
5
+ async upgrade(request, handler) {
6
+ const { response, socket } = Deno.upgradeWebSocket(request);
7
+
8
+ const controller = new AbortController();
9
+ const connection: WebSocketConnection = {
10
+ signal: controller.signal,
11
+ send(data: Uint8Array) {
12
+ socket.send(data);
13
+ },
14
+ close(code?: number, reason?: string) {
15
+ socket.close(code, reason);
16
+ },
17
+ };
18
+
19
+ socket.onopen = () => {
20
+ handler(connection);
21
+ };
22
+
23
+ socket.onclose = (ev) => {
24
+ controller.abort(`WebSocket connection closed with code ${ev.code}`);
25
+ };
26
+
27
+ return response;
28
+ },
29
+ };
30
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@atcute/xrpc-server-deno",
4
+ "version": "0.1.0",
5
+ "description": "Deno WebSocket adapter for @atcute/xrpc-server",
6
+ "license": "0BSD",
7
+ "repository": {
8
+ "url": "https://github.com/mary-ext/atcute",
9
+ "directory": "packages/servers/xrpc-server-deno"
10
+ },
11
+ "files": [
12
+ "dist/",
13
+ "lib/",
14
+ "!lib/**/*.bench.ts",
15
+ "!lib/**/*.test.ts"
16
+ ],
17
+ "exports": {
18
+ ".": "./dist/index.js"
19
+ },
20
+ "peerDependencies": {
21
+ "@atcute/xrpc-server": "^0.1.3"
22
+ },
23
+ "devDependencies": {
24
+ "@types/deno": "^2.5.0"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc --project tsconfig.build.json",
28
+ "prepublish": "rm -rf dist; pnpm run build"
29
+ }
30
+ }