Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run Linter

on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
cache: true
deno-version: v2.x

- run: deno lint
20 changes: 20 additions & 0 deletions .github/workflows/publish-dry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check Publish

on:
pull_request:
branches:
- main

jobs:
publish-dry:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4

- name: Publish package
run: npx jsr publish --dry-run
23 changes: 23 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Type Check

on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
type-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
cache: true
deno-version: v2.x

- run: deno check
12 changes: 11 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"version": "1.1.5",
"exports": "./src/index.ts",
"publish": {
"include": ["jsr.json", "LICENSE", "README.md", "src/**/*.ts"]
"include": [
"jsr.json",
"LICENSE",
"README.md",
"src/**/*.ts"
]
},
"tasks": {
"console": "deno run --watch examples/write-to-console.ts",
Expand All @@ -14,6 +19,11 @@
"useBraces": "always",
"bracePosition": "sameLineUnlessHanging"
},
"lint": {
"exclude": [
"examples/"
]
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.15",
"@std/bytes": "jsr:@std/bytes@^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/abort-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ receiver.on("event", (message) => console.log(message));

controller.abort();

console.log("Closed the socket")
console.log("Closed the socket");
9 changes: 3 additions & 6 deletions src/logReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { EventEmitter } from "node:events";
import { createSocket, type RemoteInfo, type Socket } from "node:dgram";
import { parsePacket } from "./parser.ts";
import type { EventData, TypedEventEmitter } from "./types.ts";
import type { EventData, MessageEvents, TypedEventEmitter } from "./types.ts";

/**
* The socket options for the UDP socket
Expand Down Expand Up @@ -30,10 +30,7 @@ export interface LogReceiverOptions {
signal?: AbortSignal;
}

type MessageEvents = {
error: (error: Error) => void;
event: (message: EventData) => void;
};
const LogEmitter = EventEmitter as (new () => TypedEventEmitter<MessageEvents>);

/**
* An event emitter that will emit a message event when a valid UDP log is created on the server
Expand Down Expand Up @@ -99,7 +96,7 @@ type MessageEvents = {
*
* For security reasons, you should always use a log secret to prevent evaluation of potentially malicious messages. Do this by looking at the password field. In order to set up the log secret, you can use the `sv_logsecret` command
*/
export class LogReceiver extends (EventEmitter as new () => TypedEventEmitter<MessageEvents>) implements Disposable {
export class LogReceiver extends LogEmitter implements Disposable {
#socket: Socket;

/**
Expand Down
15 changes: 15 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import type { RemoteInfo } from "node:dgram";

/**
* The possible events that can be emitted
*/
export type MessageEvents = {
/**
* Emitted when an error occurs
*/
error: (error: Error) => void;

/**
* Emitted when data is received from the server
*/
event: (message: EventData) => void;
};

/**
* Represents the parsed information from the message data
*/
Expand Down