libshv-js 3.6.3 → 3.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.6.3",
3
+ "version": "3.6.5",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/cpon.ts CHANGED
@@ -674,7 +674,7 @@ class CponWriter {
674
674
  ctx: PackContext;
675
675
  nestLevel = 0;
676
676
 
677
- constructor(private readonly indentString?: string) {
677
+ constructor(private readonly indentString?: string, private oneLiners: OneLiners = OneLiners.Yes) {
678
678
  this.ctx = new PackContext();
679
679
  }
680
680
 
@@ -949,6 +949,10 @@ class CponWriter {
949
949
  }
950
950
 
951
951
  private isOneLiner(value: MetaMap | ShvMap | IMap | List) {
952
+ if (this.oneLiners === OneLiners.No) {
953
+ return false;
954
+ }
955
+
952
956
  const keyThreshold = Array.isArray(value) ? 10 : 5;
953
957
 
954
958
  if (Array.isArray(value)) {
@@ -971,8 +975,13 @@ class CponWriter {
971
975
  }
972
976
  }
973
977
 
974
- const toCpon = (value: RpcValue, indentString?: string) => {
975
- const wr = new CponWriter(indentString);
978
+ export enum OneLiners {
979
+ Yes,
980
+ No,
981
+ }
982
+
983
+ const toCpon = (value: RpcValue, indentString?: string, oneLiners: OneLiners = OneLiners.Yes) => {
984
+ const wr = new CponWriter(indentString, oneLiners);
976
985
  wr.write(value);
977
986
  return new TextDecoder().decode(wr.ctx.buffer());
978
987
  };
package/src/ws-client.ts CHANGED
@@ -104,8 +104,6 @@ class RpcError extends Error {
104
104
  }
105
105
  }
106
106
 
107
- class ProtocolError extends Error {}
108
-
109
107
  class InvalidRequest extends RpcError {}
110
108
  class MethodNotFound extends RpcError {}
111
109
  class InvalidParams extends RpcError {}
@@ -195,7 +193,8 @@ class WsClient {
195
193
  return rpcMsg.value[RPC_MESSAGE_RESULT];
196
194
  }
197
195
 
198
- return new ProtocolError('Response included neither result nor error');
196
+ // If both result and error are missing, the result is implicitly Null.
197
+ // https://silicon-heaven.github.io/shv-doc/rpcmessage.html#response
199
198
  })());
200
199
  // eslint-disable-next-line @typescript-eslint/no-array-delete
201
200
  delete this.rpcHandlers[Number(requestId)];