Skip to content

Commit

Permalink
feat: partial v4 types
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Aug 28, 2023
1 parent 49c1d49 commit 6eb6d36
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 71 deletions.
70 changes: 70 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @description Official source identifier by lavalink itself
*/
export enum LavalinkSearchIdentifier {
YTSearch = "ytsearch",
YTMSearch = "ytmsearch",
SCSearch = "scsearch"
}

/**
* @description Official source supported by lavalink itself.
*/
export enum LavalinkSource {
Youtube = "youtube",
Soundcloud = "soundcloud",
Bandcamp = "bandcamp",
Local = "local",
Vimeo = "vimeo",
Twitch = "twitch"
}


/**
* @description A Websocket event type sent by lavalink.
*/
export enum WebSocketType {
WebSocketClosedEvent = "WebSocketClosedEvent",
TrackStartEvent = "TrackStartEvent",
TrackEndEvent = "TrackEndEvent",
TrackExceptionEvent = "TrackExceptionEvent",
TrackStuckEvent = "TrackStuckEvent"
}

/**
* @description A Websocket close code sent by discord via lavalink.
*/
export enum WebsocketCloseCode {
UnknownError = 4000,
UnknownOpCode = 4001,
DecodeError = 4002,
NotAuthenticated = 4003,
AuthenticatedError = 4004,
AlreadyAuthenticated = 4005,
SessionInvalid = 4006,
SessionTimeout = 4009,
ServerNotFound = 4011,
UnknownProtocol = 4012,
Disconnected = 4014,
VoiceServerCrashed = 4015,
UnknownEncryptionMode = 4016
}


/**
* @description Routeplanner class.
*/
export enum RoutePlannerClass {
RotatingIpRoutePlanner = "RotatingIpRoutePlanner",
NanoIpRoutePlanner = "NanoIpRoutePlanner",
RotatingNanoIpRoutePlanner = "RotatingNanoIpRoutePlanner",
BalancingIpRoutePlanner = "BalancingIpRoutePlanner"
}

/**
* @description IpBlockType.
*/
export enum IpBlockType {
INet6Address = "Inet6Address",
INet4Address = "Inet4Address"
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as V3 from "./v3";
import * as V4 from "./v4";

export { V3 };
export { V3, V4 };
4 changes: 3 additions & 1 deletion src/v3/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LavalinkSource, LoadType, Severity, WebSocketType, TrackEndReason, WebsocketCloseCode, IpBlockType, WebsocketOp, RoutePlannerClass } from "./types/index";
import { IpBlockType, LavalinkSource, RoutePlannerClass, WebSocketType, WebsocketCloseCode } from "../common";
import { LoadType, Severity, TrackEndReason, WebsocketOp } from "./types/index";

/**
* @description Lavalink track object.
Expand Down Expand Up @@ -145,6 +146,7 @@ export interface RoutePlannerStatusResponse {
};
}

export * from "../common";
export * from "./types/index";
export * from "./types/index";
export * from "./routes/index";
65 changes: 0 additions & 65 deletions src/v3/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
/**
* @description Official source identifier by lavalink itself
*/
export enum LavalinkSearchIdentifier {
YTSearch = "ytsearch",
YTMSearch = "ytmsearch",
SCSearch = "scsearch"
}

/**
* @description Official source supported by lavalink itself.
*/
export enum LavalinkSource {
Youtube = "youtube",
Soundcloud = "soundcloud",
Bandcamp = "bandcamp",
Local = "local",
Vimeo = "vimeo",
Twitch = "twitch"
}

/**
* @description A lavalink severity level when there's an error
*/
Expand All @@ -39,36 +18,6 @@ export enum LoadType {
LoadFailed = "LOAD_FAILED"
}

/**
* @description A Websocket event type sent by lavalink.
*/
export enum WebSocketType {
WebSocketClosedEvent = "WebSocketClosedEvent",
TrackStartEvent = "TrackStartEvent",
TrackEndEvent = "TrackEndEvent",
TrackExceptionEvent = "TrackExceptionEvent",
TrackStuckEvent = "TrackStuckEvent"
}

/**
* @description A Websocket close code sent by discord via lavalink.
*/
export enum WebsocketCloseCode {
UnknownError = 4000,
UnknownOpCode = 4001,
DecodeError = 4002,
NotAuthenticated = 4003,
AuthenticatedError = 4004,
AlreadyAuthenticated = 4005,
SessionInvalid = 4006,
SessionTimeout = 4009,
ServerNotFound = 4011,
UnknownProtocol = 4012,
Disconnected = 4014,
VoiceServerCrashed = 4015,
UnknownEncryptionMode = 4016
}

/**
* @description A lavalink op that sent by client.
*/
Expand Down Expand Up @@ -97,17 +46,3 @@ export enum TrackEndReason {
Cleanup = "CLEANUP"
}

/**
* @description Routeplanner class.
*/
export enum RoutePlannerClass {
RotatingNanoIPRoutePlanner = "RotatingNanoIpRoutePlanner"
}

/**
* @description IpBlockType.
*/
export enum IpBlockType {
INet6Address = "Inet6Address",
INet4Address = "Inet4Address"
}
24 changes: 24 additions & 0 deletions src/v4/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RoutePlannerClass, IpBlockType } from "../common";

/**
* @description RouteplannerStatus sent by lavalink.
*/
export interface RoutePlannerStatusResponse {
class: RoutePlannerClass;
details: {
ipBlock: {
type: IpBlockType;
size: number;
};
failingAddresses: {
failingAddress: string;
failingTimestamp: number;
failingTime: string;
}[];
blockIndex: number;
currentAddressIndex: string;
};
}

export * from "./routes";
export * from "../common";
59 changes: 59 additions & 0 deletions src/v4/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export const Routes = {
/**
* Route for:
* - GET /v4/loadtracks
*/
loadTracks(identifier: string) {
return `/v4/loadtracks?identifier=${identifier}` as const;
},
/**
* Route for:
* - GET /v4/decodetrack
*/
decodeTrack(track: string) {
return `/v4/decodetrack?track=${track}` as const;
},
/**
* Route for:
* - POST /v4/decodetracks
*/
decodeTracks() {
return "/v4/decodetracks" as const;
},
/**
* Route for:
* - GET /v4/routeplanner/status
*/
routePlannerStatus() {
return "/v4/routeplanner/status" as const;
},
/**
* Route for:
* - POST /v4/routeplanner/free/address
*/
routePlannerFreeAddress() {
return "/v4/routeplanner/free/address" as const;
},
/**
* Route for:
* - POST /v4/routeplanner/free/all
*/
routePlannerFreeAll() {
return "/v4/routeplanner/free/all" as const;
},
/**
* Route for:
* - WebSocket /v4/websocket
*/
websocket() {
return "/v4/websocket" as const;
},

/**
* Route for:
* - GET /version
*/
version() {
return "/version" as const;
}
};
32 changes: 32 additions & 0 deletions src/v4/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


/**
* @description A lavalink severity level when there's an error
*/
export enum Severity {
Common = "common",
Suspicious = "suspicious",
Fault = "failt"
}

/**
* @description A load type returned by lavalink in loadtracks route.
*/
export enum LoadType {
Track = "track",
Playlist = "playlist",
Search = "search",
Empty = "empty",
Error = "error"
}

/**
* @description A track reason when ended, sent by the lavalink server.
*/
export enum TrackEndReason {
Finished = "finished",
LoadFailed = "loadFailed",
Stopped = "stopped",
Replaced = "replaced",
Cleanup = "cleanup"
}
10 changes: 6 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"moduleResolution": "Node",
"lib": ["ES2022"],
"strict": true,
"lib": ["esnext"],
"strict": false,
"removeComments": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
Expand All @@ -14,7 +16,7 @@
"importHelpers": false,
"resolveJsonModule": true,
"strictNullChecks": true,
"typeRoots": ["node_modules/@types", "src/typings"],
"typeRoots": ["node_modules/@types"],
"declaration": true,
"declarationMap": true,
"outDir": "dist"
Expand Down

0 comments on commit 6eb6d36

Please sign in to comment.