koa-ws-socket
Advanced tools
Comparing version 0.1.1 to 1.0.0
import { Server } from 'ws'; | ||
import crypto from 'crypto'; | ||
/** | ||
* Expose compositor. | ||
*/ | ||
var koaCompose = compose; | ||
/** | ||
* Compose `middleware` returning | ||
* a fully valid middleware comprised | ||
* of all those which are passed. | ||
* | ||
* @param {Array} middleware | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
function compose (middleware) { | ||
if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!') | ||
for (const fn of middleware) { | ||
if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!') | ||
} | ||
/** | ||
* @param {Object} context | ||
* @return {Promise} | ||
* @api public | ||
*/ | ||
return function (context, next) { | ||
// last called middleware # | ||
let index = -1; | ||
return dispatch(0) | ||
function dispatch (i) { | ||
if (i <= index) return Promise.reject(new Error('next() called multiple times')) | ||
index = i; | ||
let fn = middleware[i]; | ||
if (i === middleware.length) fn = next; | ||
if (!fn) return Promise.resolve() | ||
try { | ||
return Promise.resolve(fn(context, function next () { | ||
return dispatch(i + 1) | ||
})) | ||
} catch (err) { | ||
return Promise.reject(err) | ||
} | ||
} | ||
} | ||
} | ||
function createCommonjsModule(fn, module) { | ||
@@ -207,2 +158,3 @@ return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
var compose = require('koa-compose'); | ||
var WsSocket = /** @class */ (function () { | ||
@@ -265,3 +217,3 @@ function WsSocket() { | ||
this.middleware.push(fn); | ||
this.composed = koaCompose(this.middleware); | ||
this.composed = compose(this.middleware); | ||
this.updateConnections(); | ||
@@ -268,0 +220,0 @@ return this; |
@@ -9,51 +9,2 @@ (function (global, factory) { | ||
/** | ||
* Expose compositor. | ||
*/ | ||
var koaCompose = compose; | ||
/** | ||
* Compose `middleware` returning | ||
* a fully valid middleware comprised | ||
* of all those which are passed. | ||
* | ||
* @param {Array} middleware | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
function compose (middleware) { | ||
if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!') | ||
for (const fn of middleware) { | ||
if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!') | ||
} | ||
/** | ||
* @param {Object} context | ||
* @return {Promise} | ||
* @api public | ||
*/ | ||
return function (context, next) { | ||
// last called middleware # | ||
let index = -1; | ||
return dispatch(0) | ||
function dispatch (i) { | ||
if (i <= index) return Promise.reject(new Error('next() called multiple times')) | ||
index = i; | ||
let fn = middleware[i]; | ||
if (i === middleware.length) fn = next; | ||
if (!fn) return Promise.resolve() | ||
try { | ||
return Promise.resolve(fn(context, function next () { | ||
return dispatch(i + 1) | ||
})) | ||
} catch (err) { | ||
return Promise.reject(err) | ||
} | ||
} | ||
} | ||
} | ||
function createCommonjsModule(fn, module) { | ||
@@ -213,2 +164,3 @@ return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
var compose = require('koa-compose'); | ||
var WsSocket = /** @class */ (function () { | ||
@@ -271,3 +223,3 @@ function WsSocket() { | ||
this.middleware.push(fn); | ||
this.composed = koaCompose(this.middleware); | ||
this.composed = compose(this.middleware); | ||
this.updateConnections(); | ||
@@ -274,0 +226,0 @@ return this; |
@@ -8,3 +8,3 @@ /// <reference types="node" /> | ||
import * as Koa from 'koa'; | ||
import compose from 'koa-compose'; | ||
import * as composeTypes from 'koa-compose'; | ||
import * as WebSocket from 'ws'; | ||
@@ -22,3 +22,3 @@ import Socket from './socket'; | ||
middleware: Middleware[]; | ||
composed: compose.ComposedMiddleware<SocketContext> | null; | ||
composed: composeTypes.ComposedMiddleware<SocketContext> | null; | ||
connections: Map<string, Socket>; | ||
@@ -25,0 +25,0 @@ listeners: Map<string, EventHandler[]>; |
@@ -7,3 +7,3 @@ /// <reference types="koa-compose" /> | ||
import * as WebSocket from 'ws'; | ||
import { EventHandler, Middleware, SocketContext } from './index'; | ||
import { EventHandler, SocketContext } from './index'; | ||
export default class Socket { | ||
@@ -13,4 +13,4 @@ middleware: compose.ComposedMiddleware<SocketContext> | null; | ||
request: http.ServerRequest; | ||
constructor(ws: WebSocket, request: http.ServerRequest, listeners: Map<string, EventHandler[]>, middleware: Middleware | null); | ||
update(listeners: Map<string, EventHandler[]>, middleware: Middleware | null): void; | ||
constructor(ws: WebSocket, request: http.ServerRequest, listeners: Map<string, EventHandler[]>, middleware: compose.ComposedMiddleware<SocketContext> | null); | ||
update(listeners: Map<string, EventHandler[]>, middleware: compose.ComposedMiddleware<SocketContext> | null): void; | ||
/** | ||
@@ -17,0 +17,0 @@ * Adds a specific event and callback to this socket |
@@ -1,1 +0,1 @@ | ||
{"name":"koa-ws-socket","version":"0.1.1","description":"Attaches ws sockets to koa using koa-style middleware","files":["dist"],"main":"dist/koa-ws-socket.umd.js","module":"dist/koa-ws-socket.es5.js","types":"dist/types/index.d.ts","repository":"https://github.com/pbomb/koa-ws-socket.git","author":"Matt Parrish <matt.r.parrish@gmail.com>","engines":{"node":">=6.0.0"},"license":"MIT","private":false,"scripts":{"add-contributor":"kcd-scripts contributors add","prebuild":"rimraf dist && rimraf compiled","build":"rollup --config rollup.config.ts --no-clean","lint":"tslint -c tslint.json -e **/node_modules/**/* -e **/typings/**/* **/*.ts","test":"kcd-scripts test","test:cover":"kcd-scripts test --coverage","test:update":"npm run test:cover -s -- --updateSnapshot","test:build":"kcd-scripts test --no-watch","build-and-test":"npm run build -s && npm run test:build -s","validate":"kcd-scripts validate lint,build-and-test,test:cover","precommit":"kcd-scripts precommit","prettier":"prettier --write \"**/*.ts\" \"**/*.js{,on}\"","tsc":"tsc"},"devDependencies":{"@types/jest":"21.1.2","@types/koa":"2.0.39","@types/koa-compose":"3.2.2","@types/ws":"3.2.0","kcd-scripts":"0.24.0","koa":"2.3.0","prettier":"1.7.4","rimraf":"2.6.2","rollup":"0.50.0","rollup-plugin-commonjs":"8.2.1","rollup-plugin-node-resolve":"3.0.0","rollup-plugin-sourcemaps":"0.4.2","rollup-plugin-typescript2":"0.7.0","tslint":"5.7.0","typescript":"2.5.3","ws":"3.2.0"},"peerDependencies":{"koa":">=2","ws":">=3"},"dependencies":{"base64id":"^1.0.0","koa-compose":"^4.0.0"},"release":{"analyzeCommits":{"releaseRules":[{"type":"refactor","release":"patch"}]}}} | ||
{"name":"koa-ws-socket","version":"1.0.0","description":"Attaches ws sockets to koa using koa-style middleware","files":["dist"],"main":"dist/koa-ws-socket.umd.js","module":"dist/koa-ws-socket.es5.js","types":"dist/types/index.d.ts","repository":"https://github.com/pbomb/koa-ws-socket.git","author":"Matt Parrish <matt.r.parrish@gmail.com>","engines":{"node":">=6.0.0"},"license":"MIT","private":false,"scripts":{"add-contributor":"kcd-scripts contributors add","prebuild":"rimraf dist && rimraf compiled","build":"rollup --config rollup.config.ts --no-clean","lint":"tslint -p . -c tslint.json -e **/node_modules/**/* -e **/typings/**/* **/*.ts","test":"kcd-scripts test","test:cover":"kcd-scripts test --coverage","test:update":"npm run test:cover -s -- --updateSnapshot","test:build":"kcd-scripts test --no-watch","build-and-test":"npm run build -s && npm run test:build -s","validate":"kcd-scripts validate lint,build-and-test,test:cover","precommit":"kcd-scripts precommit","prettier":"prettier --write \"**/*.ts\" \"**/*.js{,on}\"","tsc":"tsc"},"devDependencies":{"@types/jest":"21.1.5","@types/koa":"2.0.40","@types/koa-compose":"3.2.2","@types/ws":"3.2.0","kcd-scripts":"0.27.2","koa":"2.4.1","prettier":"1.8.2","rimraf":"2.6.2","rollup":"0.51.2","rollup-plugin-commonjs":"8.2.6","rollup-plugin-node-resolve":"3.0.0","rollup-plugin-sourcemaps":"0.4.2","rollup-plugin-typescript2":"0.8.0","tslint":"5.8.0","typescript":"2.6.1","ws":"3.3.1"},"peerDependencies":{"koa":">=2","ws":">=3"},"dependencies":{"base64id":"^1.0.0","koa-compose":"^4.0.0"},"release":{"analyzeCommits":{"releaseRules":[{"type":"refactor","release":"patch"}]}}} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
55605
571