Skip to content

Commit

Permalink
v6.0.0 (#35)
Browse files Browse the repository at this point in the history
* Update client.ts

* Update client.ts

* changed build option, version bumps

* fixed socket remote, logs, build module config, added node 16 target

* removed node 12 support

* updated tests, added engines check, changelog bump

* hotfix test command order

* added missing tests

* fixed linting, build order

* made broken import linter warning

Co-authored-by: Frederic Charette <[email protected]>
  • Loading branch information
fed135 and Frederic Charette authored Apr 26, 2021
1 parent bda2296 commit 47b810d
Show file tree
Hide file tree
Showing 31 changed files with 207 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"error",
{ "vars": "all", "args": "after-used", "ignoreRestSiblings": false }
],
"import/no-extraneous-dependencies": 0
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 1
},
"env": {
"browser": true,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/master-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v1
Expand All @@ -23,9 +23,9 @@ jobs:
- name: npm install, build, and test
run: |
yarn
yarn run build
yarn run lint
yarn run test
yarn run build
yarn run bench
env:
CI: true
4 changes: 2 additions & 2 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v1
Expand All @@ -23,9 +23,9 @@ jobs:
- name: npm install, build, and test
run: |
yarn
yarn run build
yarn run lint
yarn run test
yarn run build
yarn run bench
env:
CI: true
30 changes: 26 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# Changelog

## [v5.0.0] - 2020-06-23
## [v6.0.0] - 2021-04-26

commit: [#](https://github.com/kalm/kalm.js/commits)

## Breaking changes
### Breaking changes

- Client.remote is now a const instead of a function (breaking change)
- Client.local is now a const instead of a function (breaking change)
- Engines config in package.json now only allows node >=14

### Added

- Client reference in subscribe callback is now fully featured instead of a shallow config object.
- Bumped `ws` version
- Added integration tests

### Bug fixes

- Fixed importing when using typescript (breaking change)
- Fixed socket remote info
- Fixed multiple types, including opening `port` value to be a string

## [v5.0.0] - 2020-06-23

commit: [#](https://github.com/kalm/kalm.js/commit/527a245e4855f6ab7678ef4fe1ee9e7cd2ff3cb8)

### Breaking changes
- Changed default packet framing to be a pure json object
- Removed custom framing
- Added packet message cap
- Fixed multiplexing

## Added
### Added
- Added more error messages
- Added tests for transport packages
- Added CHANGELOG and LICENSE to all packages
Expand All @@ -19,7 +41,7 @@ commit: [#](https://github.com/kalm/kalm.js/commits)

commit: [731491d](https://github.com/kalm/kalm.js/commit/731491d7b98f3116e0491905c99f9ece29d24d65)

## Added
### Added
- Added more error messages
- Added tests for transport packages
- Added CHANGELOG and LICENSE to all packages
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {connect, routines} from 'kalm';
import * as ws from '@kalm/ws';
import ws from '@kalm/ws';

const client = connect({
transport: ws(),
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {listen, routines} from 'kalm';
import * as ws from '@kalm/ws';
import ws from '@kalm/ws';

const provider = listen({
transport: ws(),
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "kalm",
"private": true,
"version": "5.0.0",
"version": "6.0.0",
"description": "The socket optimizer",
"main": "packages/kalm/bin/kalm.js",
"scripts": {
"lint": "eslint **/*.ts **/*.spec.ts",
"lint": "eslint packages/**/*.ts packages/**/*.spec.ts tests/**/*.spec.ts",
"lint:fix": "yarn lint --fix",
"test": "yarn workspaces run test && yarn run test:integration",
"test:integration": "jest ./tests/integration --forceExit",
Expand Down Expand Up @@ -51,18 +51,18 @@
}
},
"devDependencies": {
"@types/jest": "^25.1.0",
"@types/node": "^13.9.0",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.0",
"husky": "^4.2.0",
"jest": "^25.1.0",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"ts-jest": "^25.2.0",
"typescript": "^3.8.0"
"@types/jest": "^26.0.0",
"@types/node": "^14.14.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.24.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"husky": "^6.0.0",
"jest": "^26.6.0",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0",
"ts-jest": "^26.5.0",
"typescript": "^4.2.0"
}
}
5 changes: 4 additions & 1 deletion packages/ipc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kalm/ipc",
"version": "5.0.0",
"version": "6.0.0",
"description": "IPC transport for Kalm",
"main": "bin/ipc.js",
"scripts": {
Expand All @@ -9,6 +9,9 @@
"test": "jest ./tests",
"prepublish": "cp ../../LICENSE ./LICENSE && cp ../../CHANGELOG.md ./CHANGELOG.md"
},
"engines": {
"node": ">=14"
},
"funding": {
"type": "Open Collective",
"url": "https://opencollective.com/kalm"
Expand Down
7 changes: 5 additions & 2 deletions packages/ipc/src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import net from 'net';
/* Methods -------------------------------------------------------------------*/

interface IPCSocket extends net.Socket {
server: {
_connectionKey: string
}
_server: {
_pipeName: string
}
Expand All @@ -25,8 +28,8 @@ function ipc({ socketTimeout = 30000, path = '/tmp/app.socket-' }: IPCConfig = {

function remote(handle: IPCSocket): Remote {
return {
host: handle && handle._server && handle._server._pipeName || null,
port: handle && handle._handle && handle._handle.fd || null,
host: handle?._server?._pipeName || handle?.server?._connectionKey || null,
port: handle?._handle?.fd || null,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/ipc/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

declare module '@kalm/ipc' {
interface IPCConfig {
socketTimeout?: number
Expand Down
5 changes: 4 additions & 1 deletion packages/kalm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kalm",
"version": "5.0.0",
"version": "6.0.0",
"description": "The socket optimizer",
"main": "bin/kalm.js",
"scripts": {
Expand All @@ -9,6 +9,9 @@
"test": "jest ./tests",
"prepublish": "cp ../../LICENSE ./LICENSE && cp ../../CHANGELOG.md ./CHANGELOG.md"
},
"engines": {
"node": ">=14"
},
"funding": {
"type": "Open Collective",
"url": "https://opencollective.com/kalm"
Expand Down
27 changes: 7 additions & 20 deletions packages/kalm/src/components/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
const routine = params.routine(params, new EventEmitter());
const socket: Socket = params.transport(params, emitter);
let totalMessages = 0;
let instance;

const remote: Remote = (params.isServer) ? socket.remote(handle) : { host: params.host, port: params.port };
const local: Remote = (params.isServer) ? { host: params.host, port: params.port } : null;

function _resolveChannel(channelName: string): Channel {
if (!(channelName in channels)) {
Expand Down Expand Up @@ -54,7 +58,7 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
channels[channelName].handlers.forEach(handler => handler(
packet,
{
client: params,
client: instance,
frame: {
channel: channelName,
id: frame.frameId,
Expand Down Expand Up @@ -105,24 +109,6 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
if (channels[channelName].handlers.length === 0 && channels[channelName].packets.length === 0) delete channels[channelName];
}

function remote(): Remote {
if (params.isServer) return socket.remote(handle);
return {
host: params.host,
port: params.port,
};
}

function local(): Remote {
if (params.isServer) {
return {
host: params.host,
port: params.port,
};
}
return null;
}

routine.emitter.on('runQueue', _wrap);
emitter.on('connect', _handleConnect);
emitter.on('disconnect', _handleDisconnect);
Expand All @@ -131,7 +117,7 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
if (!handle) log(`connecting to ${params.host}:${params.port}`);
handle = socket.connect(handle);

return Object.assign(emitter, {
instance = Object.assign(emitter, {
write,
destroy,
subscribe,
Expand All @@ -141,4 +127,5 @@ export function Client(params: ClientConfig, emitter: NodeJS.EventEmitter, handl
label: params.label,
getChannels,
});
return instance;
}
2 changes: 2 additions & 0 deletions packages/kalm/src/kalm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function validateOptions(options: ProviderConfig): void {
throw new Error('Transport is not valid, it may not have been invoked, see: https://github.com/kalm/kalm.js#documentation');
}

if (options.port && !isNaN(options.port)) options.port = +options.port;

if (options.routine) {
if (typeof options.transport !== 'function') {
throw new Error(`Routine is not a function (${options.routine}), see: https://github.com/kalm/kalm.js#documentation`);
Expand Down
8 changes: 5 additions & 3 deletions packages/kalm/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable */

declare module 'kalm' {
interface ClientConfig {
label?: string
routine?: KalmRoutine
json?: Boolean
transport?: KalmTransport
port?: number
port?: number|string
host?: string
isServer?: boolean
provider?: any
Expand Down Expand Up @@ -36,8 +38,8 @@ declare module 'kalm' {
destroy: () => void
subscribe: (channel: string, handler: (body: any, frame: Frame) => any) => void
unsubscribe: (channel: string, handler: (body: any, frame: Frame) => any) => void
local: () => Remote
remote: () => Remote
local: Remote
remote: Remote
}

type Channel = {
Expand Down
5 changes: 4 additions & 1 deletion packages/tcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kalm/tcp",
"version": "5.0.0",
"version": "6.0.0",
"description": "TCP transport for Kalm",
"main": "bin/tcp.js",
"scripts": {
Expand All @@ -9,6 +9,9 @@
"test": "jest ./tests",
"prepublish": "cp ../../LICENSE ./LICENSE && cp ../../CHANGELOG.md ./CHANGELOG.md"
},
"engines": {
"node": ">=14"
},
"funding": {
"type": "Open Collective",
"url": "https://opencollective.com/kalm"
Expand Down
13 changes: 10 additions & 3 deletions packages/tcp/src/tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import net from 'net';

/* Methods -------------------------------------------------------------------*/

interface TCPSocket extends net.Socket {
_peername: {
address: string
port: number
}
}

function tcp({ socketTimeout = 30000 }: TCPConfig = {}): KalmTransport {
return function socket(params: ClientConfig, emitter: NodeJS.EventEmitter): Socket {
let listener: net.Server;
Expand All @@ -14,10 +21,10 @@ function tcp({ socketTimeout = 30000 }: TCPConfig = {}): KalmTransport {
listener.listen(params.port, () => emitter.emit('ready'));
}

function remote(handle: net.Socket): Remote {
function remote(handle: TCPSocket): Remote {
return {
host: handle && handle.remoteAddress || null,
port: handle && handle.remotePort || null,
host: handle?.remoteAddress || handle?._peername?.address || null,
port: handle?.remotePort || handle?._peername?.port || null,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/tcp/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

declare module '@kalm/tcp' {
interface TCPConfig {
socketTimeout?: number
Expand Down
5 changes: 4 additions & 1 deletion packages/udp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kalm/udp",
"version": "5.0.0",
"version": "6.0.0",
"description": "UDP transport for Kalm",
"main": "bin/udp.js",
"scripts": {
Expand All @@ -13,6 +13,9 @@
"type": "Open Collective",
"url": "https://opencollective.com/kalm"
},
"engines": {
"node": ">=14"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kalm/kalm-js.git"
Expand Down
Loading

0 comments on commit 47b810d

Please sign in to comment.