Compare commits

...

60 Commits

Author SHA1 Message Date
semantic-release-bot acef9c9989 chore(release): 0.0.2-develop.20 [skip ci]
## [0.0.2-develop.20](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.19...v0.0.2-develop.20) (2023-10-13)
2023-10-13 10:52:11 +00:00
Derrick Hammer 46cdabf0cb
Merge remote-tracking branch 'origin/develop' into develop 2023-10-13 06:51:03 -04:00
Derrick Hammer 9a6e6f337b
dep: update kernel-protomux-client 2023-10-13 06:50:59 -04:00
semantic-release-bot 7f6da3a721 chore(release): 0.0.2-develop.19 [skip ci]
## [0.0.2-develop.19](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.18...v0.0.2-develop.19) (2023-09-03)
2023-09-03 04:44:41 +00:00
Derrick Hammer 096ef18940
Merge remote-tracking branch 'origin/develop' into develop 2023-09-03 00:43:50 -04:00
Derrick Hammer 6d0c208e71
dep: update kernel-protomux-client 2023-09-03 00:43:46 -04:00
semantic-release-bot 9f6a7db502 chore(release): 0.0.2-develop.18 [skip ci]
## [0.0.2-develop.18](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.17...v0.0.2-develop.18) (2023-09-02)
2023-09-02 14:15:29 +00:00
Derrick Hammer 28c99db8e7
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 10:14:31 -04:00
Derrick Hammer dde0708a90
dep: update kernel-protomux-client 2023-09-02 10:14:25 -04:00
semantic-release-bot 2f7e06e16f chore(release): 0.0.2-develop.17 [skip ci]
## [0.0.2-develop.17](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.16...v0.0.2-develop.17) (2023-09-02)
2023-09-02 13:18:14 +00:00
Derrick Hammer 7c0fafab4a
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 09:17:14 -04:00
Derrick Hammer 683f761d0a
dep: update kernel-protomux-client 2023-09-02 09:17:08 -04:00
semantic-release-bot a52e1e24bb chore(release): 0.0.2-develop.16 [skip ci]
## [0.0.2-develop.16](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.15...v0.0.2-develop.16) (2023-07-29)
2023-07-29 16:19:43 +00:00
Derrick Hammer 7ccd0b3c89
Merge remote-tracking branch 'origin/develop' into develop 2023-07-29 12:18:30 -04:00
Derrick Hammer 36b42578d1
dep: update kernel-protomux-client 2023-07-29 12:18:26 -04:00
semantic-release-bot a71c1b0bea chore(release): 0.0.2-develop.15 [skip ci]
## [0.0.2-develop.15](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.14...v0.0.2-develop.15) (2023-07-24)
2023-07-24 17:40:43 +00:00
Derrick Hammer 84aef2c751
Merge remote-tracking branch 'origin/develop' into develop 2023-07-24 13:39:23 -04:00
Derrick Hammer 77e9324e97
dep: update kernel-protomux-client 2023-07-24 13:39:19 -04:00
semantic-release-bot 54e89b6525 chore(release): 0.0.2-develop.14 [skip ci]
## [0.0.2-develop.14](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.13...v0.0.2-develop.14) (2023-07-23)
2023-07-23 18:44:59 +00:00
Derrick Hammer 5671c775d3
Merge remote-tracking branch 'origin/develop' into develop 2023-07-23 14:44:07 -04:00
Derrick Hammer 6223f8cda2
dep: update kernel-protomux-client 2023-07-23 14:43:58 -04:00
semantic-release-bot 2a6b52386f chore(release): 0.0.2-develop.13 [skip ci]
## [0.0.2-develop.13](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.12...v0.0.2-develop.13) (2023-07-23)
2023-07-23 00:17:32 +00:00
Derrick Hammer 5e097b1fb3
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 20:16:40 -04:00
Derrick Hammer b711ae4625
dep: update kernel-protomux-client 2023-07-22 20:16:36 -04:00
semantic-release-bot 271609cd83 chore(release): 0.0.2-develop.12 [skip ci]
## [0.0.2-develop.12](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.11...v0.0.2-develop.12) (2023-07-22)
2023-07-22 14:20:06 +00:00
Derrick Hammer d73cf9b074
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 10:19:10 -04:00
Derrick Hammer f7bbb6ece4
dep: update kernel-protomux-client 2023-07-22 10:19:06 -04:00
semantic-release-bot fca2025c3f chore(release): 0.0.2-develop.11 [skip ci]
## [0.0.2-develop.11](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.10...v0.0.2-develop.11) (2023-07-22)
2023-07-22 11:24:31 +00:00
Derrick Hammer 4aaa5c2306
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 07:23:38 -04:00
Derrick Hammer ac235131ad
dep: update kernel-protomux-client 2023-07-22 07:23:33 -04:00
semantic-release-bot 10c5fbb9d5 chore(release): 0.0.2-develop.10 [skip ci]
## [0.0.2-develop.10](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.9...v0.0.2-develop.10) (2023-07-22)
2023-07-22 10:25:08 +00:00
Derrick Hammer 7689890dcc
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 06:24:12 -04:00
Derrick Hammer b138ac0cc6
dep: update kernel-protomux-client 2023-07-22 06:24:09 -04:00
semantic-release-bot efd67b4b30 chore(release): 0.0.2-develop.9 [skip ci]
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-07-22)
2023-07-22 01:51:33 +00:00
Derrick Hammer 15ba1d8d46
Merge remote-tracking branch 'origin/develop' into develop 2023-07-21 21:50:27 -04:00
Derrick Hammer 85ff008ed6
dep: update kernel-protomux-client 2023-07-21 21:50:22 -04:00
semantic-release-bot e122c5608f chore(release): 0.0.2-develop.8 [skip ci]
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-07-22)
2023-07-22 00:43:56 +00:00
Derrick Hammer b2d3db9e93
Merge remote-tracking branch 'origin/develop' into develop 2023-07-21 20:42:44 -04:00
Derrick Hammer 61d2edc54e
dep: update kernel-protomux-client 2023-07-21 20:42:31 -04:00
semantic-release-bot 0d9a00030e chore(release): 0.0.2-develop.7 [skip ci]
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-12)
2023-07-12 10:49:51 +00:00
Derrick Hammer 6ed331a66c
Merge remote-tracking branch 'origin/develop' into develop 2023-07-12 06:48:43 -04:00
Derrick Hammer de64ddd1e5
dep: update kernel-protomux-client 2023-07-12 06:48:37 -04:00
semantic-release-bot 58bb660266 chore(release): 0.0.2-develop.6 [skip ci]
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-08)
2023-07-08 11:39:14 +00:00
Derrick Hammer cbbf085640
Merge remote-tracking branch 'origin/develop' into develop 2023-07-08 07:38:16 -04:00
Derrick Hammer f8aa950ae0
dep: update kernel-protomux-client 2023-07-08 07:38:08 -04:00
semantic-release-bot a2d7e3c302 chore(release): 0.0.2-develop.5 [skip ci]
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-08)
2023-07-08 08:15:51 +00:00
Derrick Hammer 0e29cedbe3
Merge remote-tracking branch 'origin/develop' into develop 2023-07-08 04:14:52 -04:00
Derrick Hammer 239b735b73
dep: update kernel-protomux-client 2023-07-08 04:14:49 -04:00
semantic-release-bot 68bb0320b2 chore(release): 0.0.2-develop.4 [skip ci]
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-05)
2023-07-05 03:19:35 +00:00
Derrick Hammer 626b34ad81
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 23:18:40 -04:00
Derrick Hammer 6dcd446c55
dep: update kernel-protomux-client 2023-07-04 23:18:36 -04:00
semantic-release-bot 5291ff160f chore(release): 0.0.2-develop.3 [skip ci]
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-05)
2023-07-05 01:11:00 +00:00
Derrick Hammer 7796e30f49
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 21:09:46 -04:00
Derrick Hammer 9ba5ac3102
dep: update kernel-protomux-client 2023-07-04 21:09:42 -04:00
semantic-release-bot 2e80c0c99f chore(release): 0.0.2-develop.2 [skip ci]
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-04)
2023-07-04 15:54:37 +00:00
Derrick Hammer 5df0ef6678
dep: update kernel-protomux-client 2023-07-04 11:53:16 -04:00
Derrick Hammer da8e2c1298
chore: update license based on upstream 2023-07-04 11:51:40 -04:00
semantic-release-bot 5bbdbd8548 chore(release): 0.0.2-develop.1 [skip ci]
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.1...v0.0.2-develop.1) (2023-07-04)
2023-07-04 15:45:19 +00:00
Derrick Hammer 2e7dadd19d
ci: add missing repo 2023-07-04 11:43:28 -04:00
Derrick Hammer 1fb9c77d55
refactor: move to ci and update deps 2023-07-04 06:49:05 -04:00
10 changed files with 18279 additions and 332 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

39
CHANGELOG.md Normal file
View File

@ -0,0 +1,39 @@
## [0.0.2-develop.20](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.19...v0.0.2-develop.20) (2023-10-13)
## [0.0.2-develop.19](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.18...v0.0.2-develop.19) (2023-09-03)
## [0.0.2-develop.18](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.17...v0.0.2-develop.18) (2023-09-02)
## [0.0.2-develop.17](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.16...v0.0.2-develop.17) (2023-09-02)
## [0.0.2-develop.16](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.15...v0.0.2-develop.16) (2023-07-29)
## [0.0.2-develop.15](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.14...v0.0.2-develop.15) (2023-07-24)
## [0.0.2-develop.14](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.13...v0.0.2-develop.14) (2023-07-23)
## [0.0.2-develop.13](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.12...v0.0.2-develop.13) (2023-07-23)
## [0.0.2-develop.12](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.11...v0.0.2-develop.12) (2023-07-22)
## [0.0.2-develop.11](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.10...v0.0.2-develop.11) (2023-07-22)
## [0.0.2-develop.10](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.9...v0.0.2-develop.10) (2023-07-22)
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-07-22)
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-07-22)
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-12)
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-08)
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-08)
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-05)
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-05)
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-04)
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/protomux-rpc-web/compare/v0.0.1...v0.0.2-develop.1) (2023-07-04)

45
LICENSE
View File

@ -1,37 +1,14 @@
MIT License
Copyright 2023 Holepunch Inc
Copyright 2023 Hammer Technologies LLC
Copyright (c) 2022 Hammer Technologies LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
http://www.apache.org/licenses/LICENSE-2.0
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ISC License
Copyright (c) 2022 Kasper Isager Dalsgarð <kasper@funktionel.co> & Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

44
dist/index.d.ts vendored
View File

@ -1,44 +0,0 @@
/// <reference types="node" />
import EventEmitter from "events";
export default class ProtomuxRPC extends EventEmitter {
private _id;
private _ending;
private _error?;
private _responding;
private _requests;
private _defaultValueEncoding;
private _responders;
private _channel;
private _request;
private _response;
constructor(stream: any, options?: any);
private _mux;
get mux(): any;
private _ready;
get ready(): Promise<void>;
get closed(): any;
get stream(): any;
private _init;
_onopen(handshake: any): void;
_onclose(): void;
_ondestroy(): void;
_onrequest({ id, method, value, }: {
id: number;
method: string;
value: any;
}): Promise<void>;
_onresponse({ id, error, value }: {
id: number;
error: string;
value: any;
}): void;
respond(method: string, options: Function | any, handler: Function): this;
unrespond(method: string): this;
request(method: string, value: any, options?: any): Promise<unknown>;
event(method: string, value: any, options?: any): void;
cork(): void;
uncork(): void;
end(): Promise<void>;
_endMaybe(): void;
destroy(err: Error): void;
}

224
dist/index.js vendored
View File

@ -1,224 +0,0 @@
import EventEmitter from "events";
// @ts-ignore
import Protomux from "@lumeweb/kernel-protomux-client";
// @ts-ignore
import c from "compact-encoding";
// @ts-ignore
import bitfield from "compact-encoding-bitfield";
// @ts-ignore
import bits from "bits-to-bytes";
export default class ProtomuxRPC extends EventEmitter {
_id;
_ending;
_error;
_responding;
_requests;
_defaultValueEncoding;
_responders;
_channel;
_request;
_response;
constructor(stream, options = {}) {
super();
this._mux = Protomux.from(stream);
this._defaultValueEncoding = options?.valueEncoding;
this._id = 1;
this._ending = false;
this._responding = 0;
this._requests = new Map();
this._responders = new Map();
this._ready = this._init(options);
}
_mux;
get mux() {
return this._mux;
}
_ready;
get ready() {
return this._ready;
}
get closed() {
return this._channel.closed;
}
get stream() {
return this._mux.stream;
}
async _init(options) {
this._channel = await this._mux.createChannel({
protocol: "protomux-rpc",
id: options?.id,
handshake: options?.handshake
? options?.handshakeEncoding || c.raw
: null,
onopen: this._onopen.bind(this),
onclose: this._onclose.bind(this),
ondestroy: this._ondestroy.bind(this),
});
if (this._channel === null)
throw new Error("duplicate channel");
this._request = await this._channel.addMessage({
encoding: request,
onmessage: this._onrequest.bind(this),
});
this._response = await this._channel.addMessage({
encoding: response,
onmessage: this._onresponse.bind(this),
});
await this._channel.open(options?.handshake);
}
_onopen(handshake) {
this.emit("open", handshake);
}
_onclose() {
const err = this._error || new Error("channel closed");
for (const request of this._requests.values()) {
request.reject(err);
}
this._requests.clear();
this._responders.clear();
this.emit("close");
}
_ondestroy() {
this.emit("destroy");
}
async _onrequest({ id, method, value, }) {
let error = null;
const responder = this._responders.get(method);
if (responder === undefined)
error = `unknown method '${method}'`;
else {
const { valueEncoding = this._defaultValueEncoding, requestEncoding = valueEncoding, responseEncoding = valueEncoding, } = responder.options;
if (requestEncoding)
value = c.decode(requestEncoding, value);
this._responding++;
try {
value = await responder.handler(value);
}
catch (err) {
error = err.message;
}
this._responding--;
if (!error && responseEncoding && id) {
value = c.encode(responseEncoding, value);
}
}
if (id)
this._response.send({ id, error, value });
this._endMaybe();
}
_onresponse({ id, error, value }) {
if (id === 0)
return;
const request = this._requests.get(id);
if (request === undefined)
return;
this._requests.delete(id);
if (error)
request.reject(new Error(error));
else {
const { valueEncoding = this._defaultValueEncoding, responseEncoding = valueEncoding, } = request.options;
if (responseEncoding)
value = c.decode(responseEncoding, value);
request.resolve(value);
}
this._endMaybe();
}
respond(method, options, handler) {
if (typeof options === "function") {
handler = options;
options = {};
}
this._responders.set(method, { options, handler });
return this;
}
unrespond(method) {
this._responders.delete(method);
return this;
}
async request(method, value, options = {}) {
if (this.closed)
throw new Error("channel closed");
const { valueEncoding = this._defaultValueEncoding, requestEncoding = valueEncoding, } = options;
if (requestEncoding)
value = c.encode(requestEncoding, value);
const id = this._id++;
this._request.send({ id, method, value });
return new Promise((resolve, reject) => {
this._requests.set(id, { options, resolve, reject });
});
}
event(method, value, options = {}) {
if (this.closed)
throw new Error("channel closed");
const { valueEncoding = this._defaultValueEncoding, requestEncoding = valueEncoding, } = options;
if (requestEncoding)
value = c.encode(requestEncoding, value);
this._request.send({ id: 0, method, value });
}
cork() {
this._channel.cork();
}
uncork() {
this._channel.uncork();
}
async end() {
this._ending = true;
this._endMaybe();
await EventEmitter.once(this, "close");
}
_endMaybe() {
if (this._ending && this._responding === 0 && this._requests.size === 0) {
this._channel.close();
}
}
destroy(err) {
this._error = err || new Error("channel destroyed");
this._channel.close();
}
}
const request = {
preencode(state, m) {
c.uint.preencode(state, m.id);
c.string.preencode(state, m.method);
c.raw.preencode(state, m.value);
},
encode(state, m) {
c.uint.encode(state, m.id);
c.string.encode(state, m.method);
c.raw.encode(state, m.value);
},
decode(state) {
return {
id: c.uint.decode(state),
method: c.string.decode(state),
value: c.raw.decode(state),
};
},
};
const flags = bitfield(1);
const response = {
preencode(state, m) {
flags.preencode(state);
c.uint.preencode(state, m.id);
if (m.error)
c.string.preencode(state, m.error);
else
c.raw.preencode(state, m.value);
},
encode(state, m) {
flags.encode(state, bits.of(m.error));
c.uint.encode(state, m.id);
if (m.error)
c.string.encode(state, m.error);
else
c.raw.encode(state, m.value);
},
decode(state) {
const [error] = bits.iterator(flags.decode(state));
return {
id: c.uint.decode(state),
error: error ? c.string.decode(state) : null,
value: !error ? c.raw.decode(state) : null,
};
},
};

18184
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,29 @@
{
"name": "@lumeweb/protomux-rpc-web",
"version": "0.1.0",
"version": "0.0.2-develop.20",
"type": "module",
"main": "dist/index.js",
"dependencies": {
"@lumeweb/kernel-protomux-client": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git",
"bits-to-bytes": "^1.3.0",
"compact-encoding": "^2.11.0",
"compact-encoding-bitfield": "^1.0.0",
"events": "^3.3.0",
"protomux": "^3.4.1"
},
"main": "lib/index.js",
"devDependencies": {
"@types/node": "^18.15.11",
"prettier": "^2.8.7",
"typescript": "^5.0.4"
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "*"
},
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/protomux-rpc-web.git"
},
"readme": "ERROR: No README data found!",
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"@lumeweb/kernel-protomux-client": "^0.0.2-develop.21"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
}
}

View File

@ -1,5 +1,4 @@
import EventEmitter from "events";
// @ts-ignore
import Protomux from "@lumeweb/kernel-protomux-client";
// @ts-ignore
import c from "compact-encoding";
@ -112,12 +111,13 @@ export default class ProtomuxRPC extends EventEmitter {
method: string;
value: any;
}) {
let error = null;
let error: string | null = null;
const responder = this._responders.get(method);
if (responder === undefined) error = `unknown method '${method}'`;
else {
if (responder === undefined) {
error = `unknown method '${method}'`;
} else {
const {
valueEncoding = this._defaultValueEncoding,
requestEncoding = valueEncoding,

View File

@ -1,13 +0,0 @@
{
"compilerOptions": {
"target": "esnext",
"declaration": true,
"moduleResolution": "node",
"outDir": "./dist",
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}