@axeom/ws 0.1.1

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Axeom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default,
24
+ wsPlugin: () => wsPlugin
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var wsPlugin = () => {
28
+ return (app) => {
29
+ app.ws = function(path, handlers) {
30
+ return this.addRoute(
31
+ "GET",
32
+ path,
33
+ () => {
34
+ return new Response(null, {
35
+ status: 200,
36
+ headers: {
37
+ Upgrade: "websocket",
38
+ Connection: "Upgrade",
39
+ "X-Axeom-Status": "101"
40
+ }
41
+ });
42
+ },
43
+ void 0,
44
+ { ws: handlers }
45
+ );
46
+ };
47
+ return app;
48
+ };
49
+ };
50
+ var index_default = wsPlugin;
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ wsPlugin
54
+ });
@@ -0,0 +1,27 @@
1
+ import { Axeom } from '@axeom/core';
2
+
3
+ interface WSHandlers {
4
+ open?: (ws: any) => void | Promise<void>;
5
+ message?: (ws: any, message: any) => void | Promise<void>;
6
+ close?: (ws: any, code: number, reason: string) => void | Promise<void>;
7
+ error?: (ws: any, error: any) => void | Promise<void>;
8
+ }
9
+ /**
10
+ * Axeom WebSocket Plugin.
11
+ * Adds the .ws() method to the Axeom instance.
12
+ */
13
+ declare module "@axeom/core" {
14
+ interface Axeom<T, D> {
15
+ /**
16
+ * Registers a WebSocket route.
17
+ * Triggers a '101 Switching Protocols' response and delegates to the runtime's native upgrade handler.
18
+ *
19
+ * @param path The route path.
20
+ * @param handlers WebSocket lifecycle handlers (open, message, close, etc.).
21
+ */
22
+ ws(path: string, handlers: WSHandlers): this;
23
+ }
24
+ }
25
+ declare const wsPlugin: () => <T extends Record<string, any>, D extends Record<string, any>>(app: Axeom<T, D>) => Axeom<T, D>;
26
+
27
+ export { type WSHandlers, wsPlugin as default, wsPlugin };
@@ -0,0 +1,27 @@
1
+ import { Axeom } from '@axeom/core';
2
+
3
+ interface WSHandlers {
4
+ open?: (ws: any) => void | Promise<void>;
5
+ message?: (ws: any, message: any) => void | Promise<void>;
6
+ close?: (ws: any, code: number, reason: string) => void | Promise<void>;
7
+ error?: (ws: any, error: any) => void | Promise<void>;
8
+ }
9
+ /**
10
+ * Axeom WebSocket Plugin.
11
+ * Adds the .ws() method to the Axeom instance.
12
+ */
13
+ declare module "@axeom/core" {
14
+ interface Axeom<T, D> {
15
+ /**
16
+ * Registers a WebSocket route.
17
+ * Triggers a '101 Switching Protocols' response and delegates to the runtime's native upgrade handler.
18
+ *
19
+ * @param path The route path.
20
+ * @param handlers WebSocket lifecycle handlers (open, message, close, etc.).
21
+ */
22
+ ws(path: string, handlers: WSHandlers): this;
23
+ }
24
+ }
25
+ declare const wsPlugin: () => <T extends Record<string, any>, D extends Record<string, any>>(app: Axeom<T, D>) => Axeom<T, D>;
26
+
27
+ export { type WSHandlers, wsPlugin as default, wsPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ // src/index.ts
2
+ var wsPlugin = () => {
3
+ return (app) => {
4
+ app.ws = function(path, handlers) {
5
+ return this.addRoute(
6
+ "GET",
7
+ path,
8
+ () => {
9
+ return new Response(null, {
10
+ status: 200,
11
+ headers: {
12
+ Upgrade: "websocket",
13
+ Connection: "Upgrade",
14
+ "X-Axeom-Status": "101"
15
+ }
16
+ });
17
+ },
18
+ void 0,
19
+ { ws: handlers }
20
+ );
21
+ };
22
+ return app;
23
+ };
24
+ };
25
+ var index_default = wsPlugin;
26
+ export {
27
+ index_default as default,
28
+ wsPlugin
29
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@axeom/ws",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "types": "./dist/index.d.ts",
7
+ "dependencies": {
8
+ "@axeom/core": "0.1.1"
9
+ },
10
+ "module": "./dist/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch"
24
+ }
25
+ }