@ayepi/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 +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +45 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Philip Diffenderfer
|
|
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, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @ayepi/deno
|
|
2
|
+
|
|
3
|
+
[Deno](https://deno.com) adapter for [`@ayepi/core`](https://www.npmjs.com/package/@ayepi/core).
|
|
4
|
+
Deno is fetch-native and upgrades WebSockets with the built-in
|
|
5
|
+
`Deno.upgradeWebSocket`, so this adapter has **zero dependencies** — HTTP goes
|
|
6
|
+
straight to `app.fetch` and the upgraded socket is wired to `app.ws.*`.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { serve } from 'npm:@ayepi/deno'
|
|
10
|
+
import { server } from 'npm:@ayepi/core'
|
|
11
|
+
|
|
12
|
+
const close = serve(app, { port: 3000, path: '/ws' })
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## For AI coding agents
|
|
16
|
+
|
|
17
|
+
This package ships dense, machine-oriented reference docs written for **AI coding agents**
|
|
18
|
+
(Claude Code, Cursor, and the like) to understand and drive the package — point your agent at them:
|
|
19
|
+
|
|
20
|
+
- [`ayepi-deno.md`](./ayepi-deno.md)
|
|
21
|
+
|
|
22
|
+
They live next to the source in the [repo](https://github.com/ClickerMonkey/ayepi/tree/main/packages/deno) and are **not** shipped in the npm tarball.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT © Philip Diffenderfer
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/** `WebSocket.readyState` value for an open socket (per the WHATWG spec). */
|
|
4
|
+
const WS_OPEN = 1;
|
|
5
|
+
/**
|
|
6
|
+
* Boot an ayepi app on Deno's built-in HTTP + WebSocket server.
|
|
7
|
+
*
|
|
8
|
+
* @returns a `close()` function that shuts the server down and resolves once it
|
|
9
|
+
* has finished.
|
|
10
|
+
*/
|
|
11
|
+
function serve(app, opts) {
|
|
12
|
+
const deno = globalThis.Deno;
|
|
13
|
+
if (!deno) throw new Error("@ayepi/deno: not running under Deno (no global `Deno`)");
|
|
14
|
+
const handler = (req) => {
|
|
15
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket" && (opts.path === void 0 || new URL(req.url).pathname === opts.path)) {
|
|
16
|
+
const { socket, response } = deno.upgradeWebSocket(req);
|
|
17
|
+
let conn = null;
|
|
18
|
+
socket.onopen = () => {
|
|
19
|
+
conn = app.ws.open((frame) => {
|
|
20
|
+
if (socket.readyState === WS_OPEN) socket.send(frame);
|
|
21
|
+
}, req);
|
|
22
|
+
};
|
|
23
|
+
socket.onmessage = (ev) => {
|
|
24
|
+
if (conn) app.ws.message(conn, String(ev.data));
|
|
25
|
+
};
|
|
26
|
+
socket.onclose = () => {
|
|
27
|
+
if (conn) app.ws.close(conn);
|
|
28
|
+
};
|
|
29
|
+
socket.onerror = () => {
|
|
30
|
+
if (conn) app.ws.close(conn);
|
|
31
|
+
};
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
return app.fetch(req);
|
|
35
|
+
};
|
|
36
|
+
const server = deno.serve({
|
|
37
|
+
port: opts.port,
|
|
38
|
+
hostname: opts.hostname,
|
|
39
|
+
onListen: (info) => opts.onListen?.(info)
|
|
40
|
+
}, handler);
|
|
41
|
+
return async () => {
|
|
42
|
+
await server.shutdown();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.serve = serve;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnySpec, Server } from "@ayepi/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
5
|
+
type AnyApp = Server<AnySpec>;
|
|
6
|
+
/** Options for {@link serve}. */
|
|
7
|
+
interface ServeOptions {
|
|
8
|
+
/** TCP port to listen on. */
|
|
9
|
+
readonly port: number;
|
|
10
|
+
/** Interface to bind. */
|
|
11
|
+
readonly hostname?: string;
|
|
12
|
+
/** Restrict WebSocket upgrades to this pathname (e.g. `'/ws'`). */
|
|
13
|
+
readonly path?: string;
|
|
14
|
+
/** Called once the server is listening. */
|
|
15
|
+
readonly onListen?: (info: {
|
|
16
|
+
port: number;
|
|
17
|
+
hostname: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Boot an ayepi app on Deno's built-in HTTP + WebSocket server.
|
|
22
|
+
*
|
|
23
|
+
* @returns a `close()` function that shuts the server down and resolves once it
|
|
24
|
+
* has finished.
|
|
25
|
+
*/
|
|
26
|
+
declare function serve(app: AnyApp, opts: ServeOptions): () => Promise<void>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ServeOptions, serve };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnySpec, Server } from "@ayepi/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
5
|
+
type AnyApp = Server<AnySpec>;
|
|
6
|
+
/** Options for {@link serve}. */
|
|
7
|
+
interface ServeOptions {
|
|
8
|
+
/** TCP port to listen on. */
|
|
9
|
+
readonly port: number;
|
|
10
|
+
/** Interface to bind. */
|
|
11
|
+
readonly hostname?: string;
|
|
12
|
+
/** Restrict WebSocket upgrades to this pathname (e.g. `'/ws'`). */
|
|
13
|
+
readonly path?: string;
|
|
14
|
+
/** Called once the server is listening. */
|
|
15
|
+
readonly onListen?: (info: {
|
|
16
|
+
port: number;
|
|
17
|
+
hostname: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Boot an ayepi app on Deno's built-in HTTP + WebSocket server.
|
|
22
|
+
*
|
|
23
|
+
* @returns a `close()` function that shuts the server down and resolves once it
|
|
24
|
+
* has finished.
|
|
25
|
+
*/
|
|
26
|
+
declare function serve(app: AnyApp, opts: ServeOptions): () => Promise<void>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ServeOptions, serve };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/** `WebSocket.readyState` value for an open socket (per the WHATWG spec). */
|
|
3
|
+
const WS_OPEN = 1;
|
|
4
|
+
/**
|
|
5
|
+
* Boot an ayepi app on Deno's built-in HTTP + WebSocket server.
|
|
6
|
+
*
|
|
7
|
+
* @returns a `close()` function that shuts the server down and resolves once it
|
|
8
|
+
* has finished.
|
|
9
|
+
*/
|
|
10
|
+
function serve(app, opts) {
|
|
11
|
+
const deno = globalThis.Deno;
|
|
12
|
+
if (!deno) throw new Error("@ayepi/deno: not running under Deno (no global `Deno`)");
|
|
13
|
+
const handler = (req) => {
|
|
14
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket" && (opts.path === void 0 || new URL(req.url).pathname === opts.path)) {
|
|
15
|
+
const { socket, response } = deno.upgradeWebSocket(req);
|
|
16
|
+
let conn = null;
|
|
17
|
+
socket.onopen = () => {
|
|
18
|
+
conn = app.ws.open((frame) => {
|
|
19
|
+
if (socket.readyState === WS_OPEN) socket.send(frame);
|
|
20
|
+
}, req);
|
|
21
|
+
};
|
|
22
|
+
socket.onmessage = (ev) => {
|
|
23
|
+
if (conn) app.ws.message(conn, String(ev.data));
|
|
24
|
+
};
|
|
25
|
+
socket.onclose = () => {
|
|
26
|
+
if (conn) app.ws.close(conn);
|
|
27
|
+
};
|
|
28
|
+
socket.onerror = () => {
|
|
29
|
+
if (conn) app.ws.close(conn);
|
|
30
|
+
};
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
return app.fetch(req);
|
|
34
|
+
};
|
|
35
|
+
const server = deno.serve({
|
|
36
|
+
port: opts.port,
|
|
37
|
+
hostname: opts.hostname,
|
|
38
|
+
onListen: (info) => opts.onListen?.(info)
|
|
39
|
+
}, handler);
|
|
40
|
+
return async () => {
|
|
41
|
+
await server.shutdown();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { serve };
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ayepi/deno",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Deno adapter for @ayepi/core — fetch-native HTTP + native WebSocket, zero dependencies",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/ClickerMonkey/ayepi.git",
|
|
12
|
+
"directory": "packages/deno"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/ClickerMonkey/ayepi/tree/main/packages/deno#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ClickerMonkey/ayepi/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"deno": ">=1.40.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@ayepi/core": "^0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
44
|
+
"publint": "^0.3.0",
|
|
45
|
+
"tsdown": "^0.12.0",
|
|
46
|
+
"vitest": "^2.1.8",
|
|
47
|
+
"zod": "^4.4.3",
|
|
48
|
+
"@ayepi/core": "0.1.0"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"ayepi",
|
|
52
|
+
"@ayepi/core",
|
|
53
|
+
"deno",
|
|
54
|
+
"websocket",
|
|
55
|
+
"adapter",
|
|
56
|
+
"server",
|
|
57
|
+
"fetch"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsdown",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"test": "vitest run --coverage",
|
|
63
|
+
"publint": "publint"
|
|
64
|
+
}
|
|
65
|
+
}
|