Socket
Socket
Sign inDemoInstall

@elysiajs/websocket

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elysiajs/websocket - npm Package Compare versions

Comparing version 0.0.0-experimental.7 to 0.0.0-experimental.8

32

build/es/index.js
import { Elysia as e, getPath as r } from 'elysia';
import { Router as t } from 'kingworld/src/router';
import { createValidationError as o, getSchemaValidator as s } from 'kingworld/src/utils';
import { Router as t } from 'elysia/src/router';
import { createValidationError as s, getSchemaValidator as o } from 'elysia/src/utils';
import { nanoid as a } from 'nanoid';
export const websocket = (e)=>(s)=>(s.websocketRouter = new t(), s.config.serve || (s.config.serve = {
export const websocket = (e)=>(o)=>(o.websocketRouter = new t(), o.config.serve || (o.config.serve = {
websocket: {

@@ -11,4 +11,4 @@ ...e,

if (!e.data) return;
let o = null === (t = s.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
o && o.open && o.open(e);
let s = null === (t = o.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
s && s.open && s.open(e);
},

@@ -18,3 +18,3 @@ message (e, t) {

if (!e.data) return;
let d = null === (a = s.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
let d = null === (a = o.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
if (d && d.message) {

@@ -26,11 +26,11 @@ try {

}
if ((null === (i = e.data.message) || void 0 === i ? void 0 : i.Check(t)) === !1) return void e.send(o('message', e.data.message, t).message);
if ((null === (i = e.data.message) || void 0 === i ? void 0 : i.Check(t)) === !1) return void e.send(s('message', e.data.message, t).message);
d.message(e, t);
}
},
close (e, t, o) {
close (e, t, s) {
var a;
if (!e.data) return;
let i = null === (a = s.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
i && i.close && i.close(e, t, o);
let i = null === (a = o.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
i && i.close && i.close(e, t, s);
},

@@ -40,9 +40,9 @@ drain (e) {

if (!e.data) return;
let o = null === (t = s.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
o && o.drain && o.drain(e);
let s = null === (t = o.websocketRouter.find(r((null == e ? void 0 : e.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
s && s.drain && s.drain(e);
}
}
}), s);
}), o);
e.prototype.ws = function(e, r) {
var t, o, i;
var t, s, i;
if (!this.websocketRouter) throw Error("Can't find WebSocket. Please register WebSocket plugin first");

@@ -56,3 +56,3 @@ return this.websocketRouter.register(e).ws = r, this.get(e, (e)=>{

id: a(),
message: s(null === (t = r.schema) || void 0 === t ? void 0 : t.message)
message: o(null === (t = r.schema) || void 0 === t ? void 0 : t.message)
}

@@ -64,3 +64,3 @@ })) return e.set.status = 400, 'Expected a websocket connection';

header: null === (t = r.schema) || void 0 === t ? void 0 : t.header,
params: null === (o = r.schema) || void 0 === o ? void 0 : o.params,
params: null === (s = r.schema) || void 0 === s ? void 0 : s.params,
query: null === (i = r.schema) || void 0 === i ? void 0 : i.query

@@ -67,0 +67,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), function(e, r) {
for(var t in r)Object.defineProperty(e, t, {
}), function(e, t) {
for(var r in t)Object.defineProperty(e, r, {
enumerable: !0,
get: r[t]
get: t[r]
});
}(exports, {
websocket: ()=>o,
default: ()=>a
websocket: ()=>a,
default: ()=>o
});
const e = require("elysia"), r = require("kingworld/src/router"), t = require("kingworld/src/utils"), s = require("nanoid"), o = (s)=>(o)=>(o.websocketRouter = new r.Router(), o.config.serve || (o.config.serve = {
const e = require("elysia"), t = require("elysia/src/router"), r = require("elysia/src/utils"), s = require("nanoid"), a = (s)=>(a)=>(a.websocketRouter = new t.Router(), a.config.serve || (a.config.serve = {
websocket: {
...s,
open (r) {
var t;
if (!r.data) return;
let s = null === (t = o.websocketRouter.find((0, e.getPath)((null == r ? void 0 : r.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
s && s.open && s.open(r);
open (t) {
var r;
if (!t.data) return;
let s = null === (r = a.websocketRouter.find((0, e.getPath)((null == t ? void 0 : t.data).request.url))) || void 0 === r ? void 0 : r.store.ws;
s && s.open && s.open(t);
},
message (r, s) {
var a, i;
if (!r.data) return;
let d = null === (a = o.websocketRouter.find((0, e.getPath)((null == r ? void 0 : r.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
message (t, s) {
var o, i;
if (!t.data) return;
let d = null === (o = a.websocketRouter.find((0, e.getPath)((null == t ? void 0 : t.data).request.url))) || void 0 === o ? void 0 : o.store.ws;
if (d && d.message) {

@@ -32,44 +32,44 @@ try {

}
if ((null === (i = r.data.message) || void 0 === i ? void 0 : i.Check(s)) === !1) return void r.send((0, t.createValidationError)('message', r.data.message, s).message);
d.message(r, s);
if ((null === (i = t.data.message) || void 0 === i ? void 0 : i.Check(s)) === !1) return void t.send((0, r.createValidationError)('message', t.data.message, s).message);
d.message(t, s);
}
},
close (r, t, s) {
var a;
if (!r.data) return;
let i = null === (a = o.websocketRouter.find((0, e.getPath)((null == r ? void 0 : r.data).request.url))) || void 0 === a ? void 0 : a.store.ws;
i && i.close && i.close(r, t, s);
close (t, r, s) {
var o;
if (!t.data) return;
let i = null === (o = a.websocketRouter.find((0, e.getPath)((null == t ? void 0 : t.data).request.url))) || void 0 === o ? void 0 : o.store.ws;
i && i.close && i.close(t, r, s);
},
drain (r) {
var t;
if (!r.data) return;
let s = null === (t = o.websocketRouter.find((0, e.getPath)((null == r ? void 0 : r.data).request.url))) || void 0 === t ? void 0 : t.store.ws;
s && s.drain && s.drain(r);
drain (t) {
var r;
if (!t.data) return;
let s = null === (r = a.websocketRouter.find((0, e.getPath)((null == t ? void 0 : t.data).request.url))) || void 0 === r ? void 0 : r.store.ws;
s && s.drain && s.drain(t);
}
}
}), o);
e.Elysia.prototype.ws = function(e, r) {
var o, a, i;
}), a);
e.Elysia.prototype.ws = function(e, t) {
var a, o, i;
if (!this.websocketRouter) throw Error("Can't find WebSocket. Please register WebSocket plugin first");
return this.websocketRouter.register(e).ws = r, this.get(e, (e)=>{
var o;
return this.websocketRouter.register(e).ws = t, this.get(e, (e)=>{
var a;
if (!this.server.upgrade(e.request, {
headers: 'function' == typeof r.headers ? r.headers(e) : r.headers,
headers: 'function' == typeof t.headers ? t.headers(e) : t.headers,
data: {
...e,
id: (0, s.nanoid)(),
message: (0, t.getSchemaValidator)(null === (o = r.schema) || void 0 === o ? void 0 : o.message)
message: (0, r.getSchemaValidator)(null === (a = t.schema) || void 0 === a ? void 0 : a.message)
}
})) return e.set.status = 400, 'Expected a websocket connection';
}, {
beforeHandle: r.beforeHandle,
beforeHandle: t.beforeHandle,
schema: {
header: null === (o = r.schema) || void 0 === o ? void 0 : o.header,
params: null === (a = r.schema) || void 0 === a ? void 0 : a.params,
query: null === (i = r.schema) || void 0 === i ? void 0 : i.query
header: null === (a = t.schema) || void 0 === a ? void 0 : a.header,
params: null === (o = t.schema) || void 0 === o ? void 0 : o.params,
query: null === (i = t.schema) || void 0 === i ? void 0 : i.query
}
}), this;
};
const a = o;
const o = a;
//# sourceMappingURL=index.js.map
{
"name": "@elysiajs/websocket",
"version": "0.0.0-experimental.7",
"version": "0.0.0-experimental.8",
"description": "Plugin for Elysia that add support for websocket",

@@ -16,3 +16,3 @@ "author": {

"keywords": [
"kingworld",
"elysia",
"websocket"

@@ -19,0 +19,0 @@ ],

import type { WebSocketHandler } from 'bun'
import { Elysia, getPath, type Context } from 'elysia'
import { Router } from 'kingworld/src/router'
import { createValidationError, getSchemaValidator } from 'kingworld/src/utils'
import { Router } from 'elysia/src/router'
import { createValidationError, getSchemaValidator } from 'elysia/src/utils'

@@ -13,3 +13,3 @@ import { nanoid } from 'nanoid'

/**
* Register websocket config for KingWorld
* Register websocket config for Elysia
*

@@ -19,6 +19,6 @@ * ---

* ```typescript
* import { KingWorld } from 'kingworld'
* import websocket from '@kingworldjs/websocket'
* import { Elysia } from 'elysia'
* import { websocket } from '@elysiajs/websocket'
*
* const app = new KingWorld()
* const app = new Elysia()
* .use(websocket())

@@ -25,0 +25,0 @@ * .ws('/ws', {

import type { ServerWebSocket, WebSocketHandler } from 'bun'
import type { Context, TypedSchema, HookHandler, UnwrapSchema } from 'kingworld'
import type { Router } from 'kingworld/src/router'
import type { Context, TypedSchema, HookHandler, UnwrapSchema } from 'elysia'
import type { Router } from 'elysia/src/router'
import type {
ExtractKWPath,
Handler,
KingWorldInstance,
TypedRoute,
TypedSchemaToRoute,
WithArray
} from 'kingworld/src/types'
} from 'elysia/src/types'

@@ -14,0 +12,0 @@ import type { Static, TSchema } from '@sinclair/typebox'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc