@ocap/message 1.28.5 → 1.28.7
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/README.md +1 -1
- package/lib/message.js +2 -5
- package/lib/patch.js +5 -9
- package/package.json +11 -12
package/README.md
CHANGED
package/lib/message.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
1
|
/**
|
|
3
2
|
* @fileOverview Contains basic helper methods to encode/format/mock a protobuf message
|
|
4
3
|
* @module @ocap/message
|
|
5
4
|
* @requires @ocap/util
|
|
6
5
|
* @requires @ocap/proto
|
|
7
6
|
* @example
|
|
8
|
-
*
|
|
7
|
+
* bun add @ocap/message
|
|
9
8
|
*
|
|
10
9
|
* const { createMessage, fakeMessage, formatMessage } = require('@ocap/message');
|
|
11
10
|
*/
|
|
@@ -17,7 +16,6 @@ const { Any } = require('google-protobuf/google/protobuf/any_pb');
|
|
|
17
16
|
const { Timestamp } = require('google-protobuf/google/protobuf/timestamp_pb');
|
|
18
17
|
const { toBN, bytesToHex, isUint8Array, toUint8Array } = require('@ocap/util');
|
|
19
18
|
const { enums, messages, getMessageType, toTypeUrl, fromTypeUrl, addProvider } = require('./provider');
|
|
20
|
-
// eslint-disable-next-line
|
|
21
19
|
const debug = require('debug')(`${require('../package.json').name}`);
|
|
22
20
|
|
|
23
21
|
const enumTypes = Object.keys(enums);
|
|
@@ -286,7 +284,7 @@ function createMessage(type, params) {
|
|
|
286
284
|
|
|
287
285
|
const { fn: Message, fields } = getMessageType(type);
|
|
288
286
|
if (!Message || !fields) {
|
|
289
|
-
console.error({ type, params, fields, Message });
|
|
287
|
+
console.error({ type, params, fields, Message });
|
|
290
288
|
throw new Error(`Unsupported messageType: ${type}`);
|
|
291
289
|
}
|
|
292
290
|
|
|
@@ -475,7 +473,6 @@ function encodeTimestamp(value) {
|
|
|
475
473
|
const timestamp = new Timestamp();
|
|
476
474
|
if (typeof value === 'string') {
|
|
477
475
|
const millionSeconds = Date.parse(value);
|
|
478
|
-
// eslint-disable-next-line no-restricted-globals
|
|
479
476
|
if (isNaN(millionSeconds) === false) {
|
|
480
477
|
timestamp.setSeconds(Math.floor(millionSeconds / 1e3));
|
|
481
478
|
timestamp.setNanos(Math.floor((millionSeconds % 1e3) * 1e6));
|
package/lib/patch.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
1
|
/**
|
|
3
2
|
* This patch fixes an issue in `google-protobuf` package
|
|
4
3
|
* After this patch is applied: The deserialize of `map` fields can accept empty values
|
|
@@ -10,14 +9,14 @@ const debug = require('debug')(`${require('../package.json').name}:Map`);
|
|
|
10
9
|
// FIXME: remove this patch when `google-protobuf` is enable to handle this
|
|
11
10
|
// @link https://github.com/protocolbuffers/protobuf/blob/46a48e49aa/js/map.js#L469
|
|
12
11
|
if (typeof jspb.Map.deserializeBinary === 'function' && !jspb.Map.deserializeBinary.__patched__) {
|
|
13
|
-
jspb.Map.deserializeBinary =
|
|
12
|
+
jspb.Map.deserializeBinary = (
|
|
14
13
|
map,
|
|
15
14
|
reader,
|
|
16
15
|
keyReaderFn,
|
|
17
16
|
valueReaderFn,
|
|
18
17
|
opt_valueReaderCallback,
|
|
19
18
|
opt_defaultKey = 0
|
|
20
|
-
) {
|
|
19
|
+
) => {
|
|
21
20
|
let key = opt_defaultKey;
|
|
22
21
|
let value;
|
|
23
22
|
|
|
@@ -28,11 +27,11 @@ if (typeof jspb.Map.deserializeBinary === 'function' && !jspb.Map.deserializeBin
|
|
|
28
27
|
const field = reader.getFieldNumber();
|
|
29
28
|
debug('deserializeBinary.field', field);
|
|
30
29
|
|
|
31
|
-
if (field
|
|
30
|
+
if (field === 1) {
|
|
32
31
|
// Key.
|
|
33
32
|
key = keyReaderFn.call(reader);
|
|
34
33
|
debug('deserializeBinary.key', key);
|
|
35
|
-
} else if (field
|
|
34
|
+
} else if (field === 2) {
|
|
36
35
|
debug('deserializeBinary.map', map);
|
|
37
36
|
// Value.
|
|
38
37
|
if (map.valueCtor_) {
|
|
@@ -42,10 +41,7 @@ if (typeof jspb.Map.deserializeBinary === 'function' && !jspb.Map.deserializeBin
|
|
|
42
41
|
} else {
|
|
43
42
|
value = /** @type {function(this:jspb.BinaryReader):?} */ (valueReaderFn).call(reader);
|
|
44
43
|
}
|
|
45
|
-
debug(
|
|
46
|
-
'deserializeBinary.value',
|
|
47
|
-
typeof value.toObject === 'function' ? value.toObject() : value
|
|
48
|
-
);
|
|
44
|
+
debug('deserializeBinary.value', typeof value.toObject === 'function' ? value.toObject() : value);
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/message",
|
|
3
3
|
"description": "Utility functions to encode and decode message that can send to forge",
|
|
4
|
-
"version": "1.28.
|
|
4
|
+
"version": "1.28.7",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "wangshijun",
|
|
7
7
|
"email": "shijun@arcblock.io",
|
|
@@ -18,14 +18,13 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@ocap/proto": "1.28.7",
|
|
22
|
+
"@ocap/util": "1.28.7",
|
|
21
23
|
"debug": "^4.3.6",
|
|
22
24
|
"google-protobuf": "3.21.0",
|
|
23
|
-
"lodash": "^4.17.21"
|
|
24
|
-
"@ocap/proto": "1.28.5",
|
|
25
|
-
"@ocap/util": "1.28.5"
|
|
25
|
+
"lodash": "^4.17.21"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"jest": "^29.7.0",
|
|
29
28
|
"jsdoc-to-markdown": "^7.1.1",
|
|
30
29
|
"remark-cli": "^10.0.1",
|
|
31
30
|
"remark-preset-github": "^4.0.4"
|
|
@@ -58,16 +57,16 @@
|
|
|
58
57
|
"type": "git",
|
|
59
58
|
"url": "https://github.com/ArcBlock/blockchain/tree/master/core/forge-message"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
62
60
|
"scripts": {
|
|
63
|
-
"lint": "
|
|
64
|
-
"lint:fix": "
|
|
65
|
-
"docs": "
|
|
61
|
+
"lint": "biome check",
|
|
62
|
+
"lint:fix": "biome check --write",
|
|
63
|
+
"docs": "bun run gen-dts && bun run gen-docs && bun run cleanup-docs && bun run format-docs",
|
|
66
64
|
"cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
|
|
67
65
|
"gen-docs": "jsdoc2md lib/message.js > docs/README.md",
|
|
68
66
|
"format-docs": "remark . -o",
|
|
69
67
|
"gen-dts": "j2d index.js",
|
|
70
|
-
"test": "
|
|
68
|
+
"test": "bun test",
|
|
71
69
|
"coverage": "npm run test -- --coverage"
|
|
72
|
-
}
|
|
73
|
-
|
|
70
|
+
},
|
|
71
|
+
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e"
|
|
72
|
+
}
|