@ocap/message 1.16.6 → 1.16.9

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
4
4
  [![docs](https://img.shields.io/badge/powered%20by-arcblock-green.svg)](https://docs.arcblock.io)
5
- [![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
5
+ [![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge\&utm_medium=badge\&utm_campaign=pr-badge)
6
6
 
7
7
  > Utility function to encode and format message that can be sent to or received from forge framework.
8
8
 
@@ -53,6 +53,6 @@ For full documentation, checkout [https://asset-chain.netlify.com](https://asset
53
53
 
54
54
  ## Contributors
55
55
 
56
- | Name | Website |
57
- | -------------- | -------------------------- |
58
- | **wangshijun** | <https://ocap.arcblock.io> |
56
+ | Name | Website |
57
+ | -------------- | ------------------------------- |
58
+ | **wangshijun** | <https://github.com/wangshijun> |
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Format an message from RPC to UI friendly
3
+ *
4
+ * @public
5
+ * @static
6
+ * @param {string} type - input type
7
+ * @param {object} data - input data
8
+ * @returns {object} [almost same structure as input]
9
+ */
10
+ export function formatMessage(type: string, data: object): object;
11
+ /**
12
+ * Create an protobuf encoded Typed message with specified data, ready to send to rpc server
13
+ *
14
+ * @public
15
+ * @static
16
+ * @param {string} type - message type defined in forge-proto
17
+ * @param {object} params - message content
18
+ * @returns {object} Message instance
19
+ * @example
20
+ * const { createMessage } = require('@ocap/message');
21
+ * const message = createMessage ('CreateAssetTx', {
22
+ * moniker: 'asset',
23
+ * address: 'zaAKEJRKQWsdfjksdfjkASRD',
24
+ * });
25
+ *
26
+ * message.getMoniker(); // 'asset'
27
+ * message.getAddress(); // 'zaAKEJRKQWsdfjksdfjkASRD'
28
+ * message.getReadonly(); // false
29
+ * message.setReadonly(true);
30
+ */
31
+ export function createMessage(type: string, params: object): object;
32
+ /**
33
+ * Generated a fake message for a type, the message can be RPC request/response
34
+ *
35
+ * @public
36
+ * @static
37
+ * @param {string} type - Message type string, should be defined in forge-abi or forge-core-protocol
38
+ * @returns {object}
39
+ * @example
40
+ * const { fakeMessage} = require('@ocap/message');
41
+ * const message = fakeMessage('CreateAssetTx');
42
+ * // will output
43
+ * {
44
+ * moniker: 'arcblock',
45
+ * data: { type: 'string', value: 'ABCD 1234' },
46
+ * readonly: true,
47
+ * transferrable: true,
48
+ * ttl: 2,
49
+ * parent: 'arcblock',
50
+ * address: 'F2D072CBD4954A20F26280730795D91AC1039996CEB6E24A31E9CE548DCB5E55',
51
+ * }
52
+ */
53
+ export function fakeMessage(type: string): object;
54
+ /**
55
+ * Decode an google.protobuf.Any%{ typeUrl, value } => { type, value }
56
+ *
57
+ * @public
58
+ * @static
59
+ * @param {object} data encoded data object
60
+ * @returns {object} Object%{type, value}
61
+ */
62
+ export function decodeAny(data: object): object;
63
+ /**
64
+ * Encode { type, value } => google.protobuf.Any%{ typeUrl, value }
65
+ * Does nothing on already encoded message
66
+ *
67
+ * @public
68
+ * @static
69
+ * @param {object} data
70
+ * @returns {object} google.protobuf.Any
71
+ */
72
+ export function encodeAny(data: object): object;
73
+ /**
74
+ * Convert an { seconds, nanos } | date-string to google.protobuf.Timestamp object
75
+ *
76
+ * @public
77
+ * @static
78
+ * @param {string|object} value
79
+ * @returns {object} instanceof google.protobuf.Timestamp
80
+ */
81
+ export function encodeTimestamp(value: string | object): object;
82
+ /**
83
+ * Decode google.protobuf.Timestamp message to ISO Date String
84
+ *
85
+ * FIXME: node strictly equal because we rounded the `nanos` field
86
+ *
87
+ * @public
88
+ * @static
89
+ * @param {object} data
90
+ * @returns {strong} String timestamp
91
+ */
92
+ export function decodeTimestamp(data: object): strong;
93
+ /**
94
+ * Encode BigUint and BigSint types defined in forge-sdk, double encoding is avoided
95
+ *
96
+ * @public
97
+ * @static
98
+ * @param {buffer|string|number} value - value to encode
99
+ * @param {string} type - type names defined in forge-proto
100
+ * @returns {object} Message
101
+ */
102
+ export function encodeBigInt(value: buffer | string | number, type: string): object;
103
+ /**
104
+ * Convert BigUint and BigSint to string representation of numbers
105
+ *
106
+ * @public
107
+ * @static
108
+ * @link https://stackoverflow.com/questions/23948278/how-to-convert-byte-array-into-a-signed-big-integer-in-javascript
109
+ * @param {object} data - usually from encodeBigInt
110
+ * @param {buffer} data.value
111
+ * @param {boolean} data.minus
112
+ * @returns {string} human readable number
113
+ */
114
+ export function decodeBigInt(data: {
115
+ value: buffer;
116
+ minus: boolean;
117
+ }): string;
118
+ /**
119
+ * Attach an $format method to rpc response
120
+ *
121
+ * @private
122
+ * @param {object} data
123
+ * @param {string} type
124
+ */
125
+ export function attachFormatFn(type: string, data: object, key?: string): void;
126
+ /**
127
+ * Attach an example method to
128
+ *
129
+ * @private
130
+ * @param {object} data
131
+ * @param {string} type
132
+ */
133
+ export function attachExampleFn(type: string, host: any, key: any): void;
134
+ import { addProvider } from "./provider";
135
+ import { getMessageType } from "./provider";
136
+ import { toTypeUrl } from "./provider";
137
+ import { fromTypeUrl } from "./provider";
138
+ export { addProvider, getMessageType, toTypeUrl, fromTypeUrl };
package/lib/patch.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Add type provider that can be used to format/create messages
3
+ *
4
+ * @param {object} provider - proto generated from {@see @ocap/proto}
5
+ */
6
+ export function addProvider(provider: object): void;
7
+ export function resetProviders(): void;
8
+ export const enums: {};
9
+ export const messages: {};
10
+ export function getMessageType(type: any): any;
11
+ export function toTypeUrl(type: any): any;
12
+ export function fromTypeUrl(url: any): any;
package/package.json CHANGED
@@ -1,12 +1,15 @@
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.16.6",
4
+ "version": "1.16.9",
5
5
  "author": {
6
6
  "name": "wangshijun",
7
7
  "email": "shijun@arcblock.io",
8
8
  "url": "https://github.com/wangshijun"
9
9
  },
10
+ "contributors": [
11
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
12
+ ],
10
13
  "bugs": {
11
14
  "url": "https://github.com/ArcBlock/asset-chain/issues",
12
15
  "email": "shijun@arcblock.io"
@@ -15,23 +18,22 @@
15
18
  "access": "public"
16
19
  },
17
20
  "dependencies": {
18
- "@ocap/proto": "1.16.6",
19
- "@ocap/util": "1.16.6",
21
+ "@ocap/proto": "1.16.9",
22
+ "@ocap/util": "1.16.9",
20
23
  "debug": "^4.3.3",
21
24
  "google-protobuf": "3.18.0",
22
25
  "lodash": "^4.17.21"
23
26
  },
24
27
  "devDependencies": {
25
28
  "jest": "^27.3.1",
26
- "jsdoc-to-markdown": "^5.0.0",
27
- "remark-cli": "^5.0.0",
28
- "remark-preset-github": "^0.0.9"
29
+ "jsdoc-to-markdown": "^7.1.1",
30
+ "remark-cli": "^10.0.1",
31
+ "remark-preset-github": "^4.0.1"
29
32
  },
30
33
  "remarkConfig": {
31
34
  "plugins": [
32
35
  "preset-github",
33
36
  [
34
- "validate-links",
35
37
  {
36
38
  "repository": "ArcBlock/asset-chain"
37
39
  }
@@ -40,7 +42,6 @@
40
42
  },
41
43
  "homepage": "https://github.com/ArcBlock/asset-chain/tree/master/core/forge-message",
42
44
  "keywords": [
43
- "forge",
44
45
  "blockchain",
45
46
  "arcblock",
46
47
  "sdk",
@@ -68,5 +69,5 @@
68
69
  "test": "jest --forceExit --detectOpenHandles",
69
70
  "coverage": "yarn test -- --coverage"
70
71
  },
71
- "gitHead": "c37106e25f4ac2b4e64230e5ab559bdafb5a6a7e"
72
+ "gitHead": "16fb7ce43033d07f83794914f2d5dda731f80814"
72
73
  }