Comparing version 2.0.4 to 2.0.5
@@ -5,2 +5,11 @@ # Changelog | ||
## [2.0.5][] - 2022-03-18 | ||
- Fix clients Map memory leak | ||
- Add static create method for server-side Client | ||
- Add open and close events in browser-side Client | ||
- Add common content types (MIME) to collection | ||
- Pass custom errors with `code` thrown or returned from handlers | ||
- Update dependencies | ||
## [2.0.4][] - 2021-10-12 | ||
@@ -166,3 +175,4 @@ | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v2.0.4...HEAD | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v2.0.5...HEAD | ||
[2.0.5]: https://github.com/metarhia/metacom/compare/v2.0.4...v2.0.5 | ||
[2.0.4]: https://github.com/metarhia/metacom/compare/v2.0.3...v2.0.4 | ||
@@ -169,0 +179,0 @@ [2.0.3]: https://github.com/metarhia/metacom/compare/v2.0.2...v2.0.3 |
@@ -51,2 +51,3 @@ import { EventEmitter } from './events.js'; | ||
this.connected = false; | ||
this.opening = null; | ||
this.lastActivity = new Date().getTime(); | ||
@@ -82,2 +83,3 @@ this.callTimeout = options.callTimeout || CALL_TIMEOUT; | ||
const [resolve, reject] = promised; | ||
this.calls.delete(callId); | ||
if (packet.error) { | ||
@@ -138,2 +140,3 @@ reject(new MetacomError(packet.error)); | ||
const target = interfaceName + '/' + methodName; | ||
if (this.opening) await this.opening; | ||
if (!this.connected) await this.open(); | ||
@@ -157,2 +160,3 @@ return new Promise((resolve, reject) => { | ||
async open() { | ||
if (this.opening) return this.opening; | ||
if (this.connected) return; | ||
@@ -172,3 +176,5 @@ const socket = new WebSocket(this.url); | ||
socket.addEventListener('close', () => { | ||
this.opening = null; | ||
this.connected = false; | ||
this.emit('close'); | ||
setTimeout(() => { | ||
@@ -191,8 +197,11 @@ if (this.active) this.open(); | ||
return new Promise((resolve) => { | ||
this.opening = new Promise((resolve) => { | ||
socket.addEventListener('open', () => { | ||
this.opening = null; | ||
this.connected = true; | ||
this.emit('open'); | ||
resolve(); | ||
}); | ||
}); | ||
return this.opening; | ||
} | ||
@@ -219,2 +228,3 @@ | ||
this.connected = true; | ||
this.emit('open'); | ||
} | ||
@@ -221,0 +231,0 @@ |
@@ -139,5 +139,7 @@ 'use strict'; | ||
} catch (error) { | ||
const timedout = error.message === 'Timeout reached'; | ||
const code = timedout ? 408 : 500; | ||
this.error(code, { callId, error, pass: timedout }); | ||
if (error.message === 'Timeout reached') { | ||
error.code = error.httpCode = 408; | ||
} | ||
const httpCode = error.httpCode || error.code; | ||
this.error(error.code, { callId, error, httpCode }); | ||
return; | ||
@@ -147,4 +149,5 @@ } finally { | ||
} | ||
if (typeof result === 'object' && result.constructor.name === 'Error') { | ||
this.error(result.code, { callId, error: result, pass: true }); | ||
if (result && result.constructor && result.constructor.name === 'Error') { | ||
const { code, httpCode } = result; | ||
this.error(code, { callId, error: result, httpCode: httpCode || 200 }); | ||
return; | ||
@@ -157,9 +160,9 @@ } | ||
error(code, { callId, error = null, pass = false } = {}) { | ||
error(code = 500, { callId, error = null, httpCode = 500 } = {}) { | ||
const { req, ip, application } = this; | ||
const { url, method } = req; | ||
const status = http.STATUS_CODES[code]; | ||
const message = pass ? error.message : status || 'Unknown error'; | ||
const httpCode = status ? code : 500; | ||
const reason = `${httpCode}\t${error ? error.stack : status}`; | ||
const status = http.STATUS_CODES[httpCode]; | ||
const pass = httpCode < 500 || httpCode > 599; | ||
const message = pass && error ? error.message : status || 'Unknown error'; | ||
const reason = `${httpCode}\t${code}\t${error ? error.stack : status}`; | ||
application.console.error(`${ip}\t${method}\t${url}\t${reason}`); | ||
@@ -166,0 +169,0 @@ const packet = { callback: callId, error: { message, code } }; |
@@ -49,2 +49,3 @@ 'use strict'; | ||
const [resolve, reject] = promised; | ||
this.calls.delete(callId); | ||
if (packet.error) { | ||
@@ -64,2 +65,6 @@ reject(new MetacomError(packet.error)); | ||
static create(url) { | ||
return new Metacom(url); | ||
} | ||
ready() { | ||
@@ -66,0 +71,0 @@ return new Promise((resolve) => { |
@@ -7,9 +7,63 @@ 'use strict'; | ||
const MIME_TYPES = { | ||
html: 'text/html; charset=UTF-8', | ||
json: 'application/json; charset=UTF-8', | ||
js: 'application/javascript; charset=UTF-8', | ||
bin: 'application/octet-stream', | ||
htm: 'text/html', | ||
html: 'text/html', | ||
shtml: 'text/html', | ||
json: 'application/json', | ||
xml: 'text/xml', | ||
js: 'application/javascript', | ||
mjs: 'application/javascript', | ||
css: 'text/css', | ||
txt: 'text/plain', | ||
csv: 'text/csv', | ||
ics: 'text/calendar', | ||
avif: 'image/avif', | ||
bmp: 'image/x-ms-bmp', | ||
gif: 'image/gif', | ||
ico: 'image/x-icon', | ||
jng: 'image/x-jng', | ||
jpg: 'image/jpg', | ||
png: 'image/png', | ||
ico: 'image/x-icon', | ||
svg: 'image/svg+xml', | ||
svgz: 'image/svg+xml', | ||
tiff: 'image/tiff', | ||
tif: 'image/tiff', | ||
wbmp: 'image/vnd.wap.wbmp', | ||
webp: 'image/webp', | ||
'3gpp': 'video/3gpp', | ||
'3gp': 'video/3gpp', | ||
aac: 'audio/aac', | ||
asf: 'video/x-ms-asf', | ||
avi: 'video/x-msvideo', | ||
m4a: 'audio/x-m4a', | ||
mid: 'audio/midi', | ||
midi: 'audio/midi', | ||
mov: 'video/quicktime', | ||
mp3: 'audio/mpeg', | ||
mp4: 'video/mp4', | ||
mpega: 'video/mpeg', | ||
mpeg: 'video/mpeg', | ||
mpg: 'video/mpeg', | ||
oga: 'audio/ogg', | ||
ogv: 'video/ogg', | ||
ra: 'audio/x-realaudio', | ||
wav: 'audio/wav', | ||
weba: 'audio/webm', | ||
webm: 'video/webm', | ||
otf: 'font/otf', | ||
ttf: 'font/ttf', | ||
woff: 'font/woff', | ||
woff2: 'font/woff2', | ||
ai: 'application/postscript', | ||
eps: 'application/postscript', | ||
jar: 'application/java-archive', | ||
pdf: 'application/pdf', | ||
ps: 'application/postscript', | ||
wasm: 'application/wasm', | ||
'7z': 'application/x-7z-compressed', | ||
gz: 'application/gzip', | ||
rar: 'application/x-rar-compressed', | ||
tar: 'application/x-tar', | ||
tgz: 'application/gzip', | ||
zip: 'application/zip', | ||
}; | ||
@@ -16,0 +70,0 @@ |
{ | ||
"name": "metacom", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -53,20 +53,20 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access", | ||
"engines": { | ||
"node": "^12.9 || 14 || 16" | ||
"node": "^12.9 || 14 || 16 || 17" | ||
}, | ||
"dependencies": { | ||
"metautil": "^3.5.16", | ||
"ws": "^8.2.3" | ||
"metautil": "^3.5.19", | ||
"ws": "^8.5.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.10.4", | ||
"@types/ws": "^8.2.0", | ||
"eslint": "^7.31.0", | ||
"@types/node": "^17.0.21", | ||
"@types/ws": "^8.5.3", | ||
"eslint": "^8.11.0", | ||
"eslint-config-metarhia": "^7.0.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.25.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"metatests": "^0.7.2", | ||
"prettier": "^2.4.1", | ||
"typescript": "^4.4.4" | ||
"metatests": "^0.8.2", | ||
"prettier": "^2.6.0", | ||
"typescript": "^4.6.2" | ||
} | ||
} |
# Metacom Communication Protocol for Metarhia | ||
[![ci status](https://github.com/metarhia/metacom/workflows/Testing%20CI/badge.svg)](https://github.com/metarhia/metacom/actions?query=workflow%3A%22Testing+CI%22+branch%3Amaster) | ||
[![codacy](https://api.codacy.com/project/badge/Grade/80885bfdb4bd411da51f31a7593c1f65)](https://www.codacy.com/app/metarhia/metacom) | ||
[![snyk](https://snyk.io/test/github/metarhia/metacom/badge.svg)](https://snyk.io/test/github/metarhia/metacom) | ||
@@ -6,0 +5,0 @@ [![npm version](https://badge.fury.io/js/metacom.svg)](https://badge.fury.io/js/metacom) |
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
40544
988
33
Updatedmetautil@^3.5.19
Updatedws@^8.5.0