ronds-metadata 1.2.37 → 1.2.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/es/api/index.js +83 -131
  2. package/es/comps/DynamicPorts/comps/ContextMenu.js +3 -11
  3. package/es/comps/DynamicPorts/comps/DragNode.js +3 -8
  4. package/es/comps/DynamicPorts/comps/GraphHandler/index.js +4 -5
  5. package/es/comps/DynamicPorts/comps/NodeElement.js +1 -4
  6. package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +3 -6
  7. package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +3 -7
  8. package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +18 -21
  9. package/es/comps/DynamicPorts/comps/shape/edge.js +5 -18
  10. package/es/comps/DynamicPorts/comps/shape/node.js +4 -17
  11. package/es/comps/DynamicPorts/constant/index.js +2 -5
  12. package/es/comps/DynamicPorts/graph.d.ts +2 -2
  13. package/es/comps/DynamicPorts/graph.js +228 -312
  14. package/es/comps/DynamicPorts/index.js +39 -58
  15. package/es/comps/DynamicPorts/utils.js +21 -25
  16. package/es/comps/Editable/DataCell/ButtonCell.js +4 -10
  17. package/es/comps/Editable/DataCell/ColorPicker.js +2 -7
  18. package/es/comps/Editable/DataCell/Input.js +5 -14
  19. package/es/comps/Editable/DataCell/Number.js +3 -10
  20. package/es/comps/Editable/DataCell/Select.js +7 -14
  21. package/es/comps/Editable/DataCell/Switch.js +2 -7
  22. package/es/comps/Editable/comps/EditableAction.js +8 -12
  23. package/es/comps/Editable/comps/EditableCell.js +16 -26
  24. package/es/comps/Editable/comps/EditableHeardCell.js +21 -34
  25. package/es/comps/Editable/comps/EditableRow.js +49 -59
  26. package/es/comps/Editable/comps/Texty.js +40 -73
  27. package/es/comps/Editable/index.js +67 -112
  28. package/es/comps/Editable/interface.d.ts +1 -1
  29. package/es/comps/Editable/utils.js +0 -1
  30. package/es/comps/FileView/index.js +65 -101
  31. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +8 -13
  32. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +8 -4
  33. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +6 -2
  34. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +8 -4
  35. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +6 -11
  36. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +6 -10
  37. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +6 -2
  38. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +6 -11
  39. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +8 -4
  40. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +8 -13
  41. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +6 -10
  42. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +6 -2
  43. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +6 -11
  44. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +6 -3
  45. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +2 -5
  46. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +86 -109
  47. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +3 -7
  48. package/es/comps/FormGenerator/comps/Canvas/core/index.js +54 -91
  49. package/es/comps/FormGenerator/comps/Canvas/index.js +8 -15
  50. package/es/comps/FormGenerator/comps/Settings/index.js +16 -30
  51. package/es/comps/FormGenerator/comps/Sidebar/Elements.js +23 -22
  52. package/es/comps/FormGenerator/comps/Sidebar/index.js +6 -2
  53. package/es/comps/FormGenerator/index.js +3 -9
  54. package/es/comps/FormGenerator/interface.d.ts +1 -1
  55. package/es/comps/FormGenerator/settings/index.js +12 -11
  56. package/es/comps/FormGenerator/settings/ruleConfig.js +0 -1
  57. package/es/comps/FormGenerator/transformer.js +40 -105
  58. package/es/comps/Icons/index.js +4 -7
  59. package/es/comps/JsonEdit/index.js +25 -50
  60. package/es/comps/JsonView/index.js +7 -21
  61. package/es/comps/MdEdit/index.js +7 -10
  62. package/es/comps/MdEditPro/index.d.ts +10 -0
  63. package/es/comps/MdEditPro/index.js +22 -0
  64. package/es/comps/MdEditPro/index.less +74 -0
  65. package/es/comps/MdNavbar/index.js +17 -40
  66. package/es/comps/MdNavbar/utils.js +0 -4
  67. package/es/comps/MdView/index.js +7 -11
  68. package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +129 -183
  69. package/es/comps/MetadataEdit/components/MetaPropsEdit.js +11 -27
  70. package/es/comps/MetadataEdit/hooks/index.js +3 -11
  71. package/es/comps/MetadataEdit/index.js +25 -58
  72. package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +17 -33
  73. package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +15 -29
  74. package/es/comps/MetadataEditV2/hooks/index.js +5 -12
  75. package/es/comps/MetadataEditV2/index.js +30 -65
  76. package/es/comps/MetadataForm/DataCell/Array.js +12 -23
  77. package/es/comps/MetadataForm/DataCell/Input.js +23 -39
  78. package/es/comps/MetadataForm/DataCell/Number.js +10 -21
  79. package/es/comps/MetadataForm/DataCell/Ref.js +87 -121
  80. package/es/comps/MetadataForm/DataCell/Select.js +131 -226
  81. package/es/comps/MetadataForm/DataCell/Switch.js +7 -14
  82. package/es/comps/MetadataForm/DataCell/layout/TableArray.js +98 -169
  83. package/es/comps/MetadataForm/HOC/index.js +20 -37
  84. package/es/comps/MetadataForm/hooks/index.js +12 -38
  85. package/es/comps/MetadataForm/index.js +37 -72
  86. package/es/comps/MetadataForm/interface.d.ts +3 -3
  87. package/es/comps/MetadataForm/utils.d.ts +1 -0
  88. package/es/comps/MetadataForm/utils.js +12 -14
  89. package/es/comps/Split/index.js +40 -38
  90. package/es/config.js +0 -4
  91. package/es/framework/RxStore/demo/index.js +9 -10
  92. package/es/framework/RxStore/hooks.d.ts +9 -9
  93. package/es/framework/RxStore/hooks.js +10 -35
  94. package/es/framework/RxStore/store.d.ts +4 -4
  95. package/es/framework/RxStore/store.js +0 -10
  96. package/es/framework/fg/index.js +18 -80
  97. package/es/framework/fg/interface.d.ts +2 -2
  98. package/es/framework/fg/utils.js +0 -10
  99. package/es/framework/graph/index.d.ts +2 -2
  100. package/es/framework/graph/index.js +55 -110
  101. package/es/framework/hooks/use-async-memo.js +3 -7
  102. package/es/framework/hooks/use-sync-scroll.js +2 -15
  103. package/es/framework/http/cache.js +25 -32
  104. package/es/framework/http/cancel.js +1 -7
  105. package/es/framework/http/index.js +22 -82
  106. package/es/framework/http/msgpack.js +0 -4
  107. package/es/framework/http/msgpack5/index.js +2 -12
  108. package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +1 -13
  109. package/es/framework/http/msgpack5/lib/decoder.js +10 -68
  110. package/es/framework/http/msgpack5/lib/encoder.js +8 -36
  111. package/es/framework/http/msgpack5/lib/helpers.js +3 -2
  112. package/es/framework/http/msgpack5/lib/streams.js +0 -18
  113. package/es/framework/libs/jquery.min.js +1009 -1696
  114. package/es/framework/locale/dil8/di18n.js +4 -15
  115. package/es/framework/locale/dil8/translate.js +0 -14
  116. package/es/framework/locale/dil8/util.js +0 -3
  117. package/es/framework/locale/index.js +2 -3
  118. package/es/framework/metadata/MetadataService.js +39 -78
  119. package/es/framework/metadata/index.js +4 -70
  120. package/es/framework/rxjs-hooks/useMemoSubject.js +0 -2
  121. package/es/framework/rxjs-hooks/useObservable.js +2 -4
  122. package/es/framework/rxjs-hooks/useObservableState.js +8 -14
  123. package/es/index.d.ts +1 -0
  124. package/es/index.js +2 -1
  125. package/es/utils.js +58 -97
  126. package/package.json +4 -2
  127. package/es/comps/MdEdit/plugin/EditContent.d.ts +0 -5
  128. package/es/comps/MdEdit/plugin/EditContent.js +0 -34
  129. package/es/comps/MdEdit/plugin/Mark.d.ts +0 -7
  130. package/es/comps/MdEdit/plugin/Mark.js +0 -60
  131. package/es/framework/libs/iconfont/iconfont.json +0 -401
@@ -1,10 +1,8 @@
1
1
  var type = -1;
2
-
3
2
  function encode(dt) {
4
3
  var millis = dt * 1;
5
4
  var seconds = Math.floor(millis / 1000);
6
5
  var nanos = (millis - seconds * 1000) * 1e6;
7
-
8
6
  if (nanos || seconds > 0xffffffff) {
9
7
  // Timestamp64
10
8
  var encoded = Buffer.allocUnsafe(9);
@@ -19,30 +17,23 @@ function encode(dt) {
19
17
  } else {
20
18
  // Timestamp32
21
19
  var _encoded = Buffer.allocUnsafe(5);
22
-
23
20
  _encoded[0] = -1;
24
-
25
21
  _encoded.writeUInt32BE(Math.floor(millis / 1000), 1);
26
-
27
22
  return _encoded;
28
23
  }
29
24
  }
30
-
31
25
  function check(obj) {
32
26
  return typeof obj.getDate === 'function';
33
27
  }
34
-
35
28
  function decode(buf) {
36
29
  // console.log(buf, 'msgpack');
37
30
  var seconds;
38
31
  var nanoseconds = 0;
39
-
40
32
  switch (buf.length) {
41
33
  case 4:
42
34
  // timestamp 32 stores the number of seconds that have elapsed since 1970-01-01 00:00:00 UTC in an 32-bit unsigned integer
43
35
  seconds = buf.readUInt32BE(0);
44
36
  break;
45
-
46
37
  case 8:
47
38
  // Timestamp 64 stores the number of seconds and nanoseconds that have elapsed
48
39
  // since 1970-01-01 00:00:00 UTC in 32-bit unsigned integers, split 30/34 bits
@@ -50,19 +41,16 @@ function decode(buf) {
50
41
  var lower = buf.readUInt32BE(4);
51
42
  nanoseconds = upper / 4;
52
43
  seconds = (upper & 0x03) * Math.pow(2, 32) + lower; // If we use bitwise operators, we get truncated to 32bits
53
-
54
44
  break;
55
- // 修改了下这里 不让他报错
56
45
 
46
+ // 修改了下这里 不让他报错
57
47
  case 12:
58
48
  // throw new Error('timestamp 96 is not yet implemented');
59
49
  return undefined;
60
50
  }
61
-
62
51
  var millis = seconds * 1000 + Math.round(nanoseconds / 1e6);
63
52
  return new Date(millis);
64
53
  }
65
-
66
54
  module.exports = {
67
55
  check: check,
68
56
  type: type,
@@ -32,27 +32,22 @@ var SIZES = {
32
32
  0xdc: 3,
33
33
  0xdd: 5
34
34
  };
35
-
36
35
  function isValidDataSize(dataLength, bufLength, headerLength) {
37
36
  return bufLength >= headerLength + dataLength;
38
37
  }
39
-
40
38
  export function buildDecode(decodingTypes) {
41
39
  return decode;
42
-
43
40
  function decode(buf) {
44
41
  // TODO: Make it into ensureBl handler ?
45
42
  if (!(buf instanceof bl)) {
46
43
  buf = bl().append(buf);
47
44
  }
48
-
49
- var result = tryDecode(buf, 0); // Handle worst case ASAP and keep code flat
50
-
45
+ var result = tryDecode(buf, 0);
46
+ // Handle worst case ASAP and keep code flat
51
47
  if (!result) throw new IncompleteBufferError();
52
48
  buf.consume(result[1]);
53
49
  return result[0];
54
50
  }
55
-
56
51
  function tryDecode(buf, initialOffset) {
57
52
  if (buf.length <= initialOffset) return null;
58
53
  var bufLength = buf.length - initialOffset;
@@ -61,206 +56,155 @@ export function buildDecode(decodingTypes) {
61
56
  offset += 1;
62
57
  var size = SIZES[first] || -1;
63
58
  if (bufLength < size) return null;
64
-
65
59
  var inRange = function inRange(start, end) {
66
60
  return first >= start && first <= end;
67
61
  };
68
-
69
62
  if (first < 0x80) return [first, 1]; // 7-bits positive ints
70
-
71
63
  if ((first & 0xf0) === 0x80) {
72
64
  var length = first & 0x0f;
73
- var headerSize = offset - initialOffset; // we have an array with less than 15 elements
74
-
65
+ var headerSize = offset - initialOffset;
66
+ // we have an array with less than 15 elements
75
67
  return decodeMap(buf, offset, length, headerSize);
76
68
  }
77
-
78
69
  if ((first & 0xf0) === 0x90) {
79
70
  var _length = first & 0x0f;
80
-
81
- var _headerSize = offset - initialOffset; // we have a map with less than 15 elements
82
-
83
-
71
+ var _headerSize = offset - initialOffset;
72
+ // we have a map with less than 15 elements
84
73
  return decodeArray(buf, offset, _length, _headerSize);
85
74
  }
86
-
87
75
  if ((first & 0xe0) === 0xa0) {
88
76
  // fixstr up to 31 bytes
89
77
  var _length2 = first & 0x1f;
90
-
91
78
  if (!isValidDataSize(_length2, bufLength, 1)) return null;
92
79
  var result = buf.toString('utf8', offset, offset + _length2);
93
80
  return [result, _length2 + 1];
94
81
  }
95
-
96
82
  if (inRange(0xc0, 0xc3)) return decodeConstants(first);
97
-
98
83
  if (inRange(0xc4, 0xc6)) {
99
84
  var _length3 = buf.readUIntBE(offset, size - 1);
100
-
101
85
  offset += size - 1;
102
86
  if (!isValidDataSize(_length3, bufLength, size)) return null;
103
-
104
87
  var _result = buf.slice(offset, offset + _length3);
105
-
106
88
  return [_result, size + _length3];
107
89
  }
108
-
109
90
  if (inRange(0xc7, 0xc9)) {
110
91
  var _length4 = buf.readUIntBE(offset, size - 2);
111
-
112
92
  offset += size - 2;
113
-
114
93
  var _type = buf.readInt8(offset);
115
-
116
94
  offset += 1;
117
95
  if (!isValidDataSize(_length4, bufLength, size)) return null;
118
96
  return decodeExt(buf, offset, _type, _length4, size);
119
97
  }
120
-
121
98
  if (inRange(0xca, 0xcb)) return decodeFloat(buf, offset, size - 1);
122
99
  if (inRange(0xcc, 0xcf)) return decodeUnsignedInt(buf, offset, size - 1);
123
100
  if (inRange(0xd0, 0xd3)) return decodeSigned(buf, offset, size - 1);
124
-
125
101
  if (inRange(0xd4, 0xd8)) {
126
102
  var type = buf.readInt8(offset); // Signed
127
-
128
103
  offset += 1;
129
104
  return decodeExt(buf, offset, type, size - 2, 2);
130
105
  }
131
-
132
106
  if (inRange(0xd9, 0xdb)) {
133
107
  var _length5 = buf.readUIntBE(offset, size - 1);
134
-
135
108
  offset += size - 1;
136
109
  if (!isValidDataSize(_length5, bufLength, size)) return null;
137
-
138
110
  var _result2 = buf.toString('utf8', offset, offset + _length5);
139
-
140
111
  return [_result2, size + _length5];
141
112
  }
142
-
143
113
  if (inRange(0xdc, 0xdd)) {
144
114
  var _length6 = buf.readUIntBE(offset, size - 1);
145
-
146
115
  offset += size - 1;
147
116
  return decodeArray(buf, offset, _length6, size);
148
117
  }
149
-
150
118
  if (inRange(0xde, 0xdf)) {
151
119
  var _length7;
152
-
153
120
  switch (first) {
154
121
  case 0xde:
155
122
  // maps up to 2^16 elements - 2 bytes
156
123
  _length7 = buf.readUInt16BE(offset);
157
- offset += 2; // console.log(offset - initialOffset)
158
-
124
+ offset += 2;
125
+ // console.log(offset - initialOffset)
159
126
  return decodeMap(buf, offset, _length7, 3);
160
-
161
127
  case 0xdf:
162
128
  _length7 = buf.readUInt32BE(offset);
163
129
  offset += 4;
164
130
  return decodeMap(buf, offset, _length7, 5);
165
131
  }
166
132
  }
167
-
168
133
  if (first >= 0xe0) return [first - 0x100, 1]; // 5 bits negative ints
169
134
 
170
135
  throw new Error('not implemented yet');
171
136
  }
172
-
173
137
  function decodeArray(buf, initialOffset, length, headerLength) {
174
138
  var offset = initialOffset;
175
139
  var result = [];
176
140
  var i = 0;
177
-
178
141
  while (i++ < length) {
179
142
  var decodeResult = tryDecode(buf, offset);
180
143
  if (!decodeResult) return null;
181
144
  result.push(decodeResult[0]);
182
145
  offset += decodeResult[1];
183
146
  }
184
-
185
147
  return [result, headerLength + offset - initialOffset];
186
148
  }
187
-
188
149
  function decodeMap(buf, offset, length, headerLength) {
189
150
  var _temp = decodeArray(buf, offset, 2 * length, headerLength);
190
-
191
151
  if (!_temp) return null;
192
-
193
152
  var _temp2 = _slicedToArray(_temp, 2),
194
- result = _temp2[0],
195
- consumedBytes = _temp2[1];
196
-
153
+ result = _temp2[0],
154
+ consumedBytes = _temp2[1];
197
155
  var isPlainObject = true;
198
-
199
156
  for (var i = 0; i < 2 * length; i += 2) {
200
157
  if (typeof result[i] !== 'string') {
201
158
  isPlainObject = false;
202
159
  break;
203
160
  }
204
161
  }
205
-
206
162
  if (isPlainObject) {
207
163
  var object = {};
208
-
209
164
  for (var _i = 0; _i < 2 * length; _i += 2) {
210
165
  var key = result[_i];
211
166
  var val = result[_i + 1];
212
167
  object[key] = val;
213
168
  }
214
-
215
169
  return [object, consumedBytes];
216
170
  } else {
217
171
  var mapping = new Map();
218
-
219
172
  for (var _i2 = 0; _i2 < 2 * length; _i2 += 2) {
220
173
  var _key = result[_i2];
221
174
  var _val = result[_i2 + 1];
222
175
  mapping.set(_key, _val);
223
176
  }
224
-
225
177
  return [mapping, consumedBytes];
226
178
  }
227
179
  }
228
-
229
180
  function readInt64BE(buf, offset) {
230
181
  var negate = (buf[offset] & 0x80) == 0x80; // eslint-disable-line
231
182
 
232
183
  if (negate) {
233
184
  var carry = 1;
234
-
235
185
  for (var i = offset + 7; i >= offset; i--) {
236
186
  var v = (buf[i] ^ 0xff) + carry;
237
187
  buf[i] = v & 0xff;
238
188
  carry = v >> 8;
239
189
  }
240
190
  }
241
-
242
191
  var hi = buf.readUInt32BE(offset + 0);
243
192
  var lo = buf.readUInt32BE(offset + 4);
244
193
  return (hi * 4294967296 + lo) * (negate ? -1 : +1);
245
194
  }
246
-
247
195
  function decodeUnsignedInt(buf, offset, size) {
248
196
  var maxOffset = offset + size;
249
197
  var result = 0;
250
-
251
198
  while (offset < maxOffset) {
252
199
  result += buf.readUInt8(offset++) * Math.pow(256, maxOffset - offset);
253
200
  }
254
-
255
201
  return [result, size + 1];
256
202
  }
257
-
258
203
  function decodeConstants(first) {
259
204
  if (first === 0xc0) return [null, 1];
260
205
  if (first === 0xc2) return [false, 1];
261
206
  if (first === 0xc3) return [true, 1];
262
207
  }
263
-
264
208
  function decodeSigned(buf, offset, size) {
265
209
  var result;
266
210
  if (size === 1) result = buf.readInt8(offset);
@@ -269,14 +213,12 @@ export function buildDecode(decodingTypes) {
269
213
  if (size === 8) result = readInt64BE(buf.slice(offset, offset + 8), 0);
270
214
  return [result, size + 1];
271
215
  }
272
-
273
216
  function decodeFloat(buf, offset, size) {
274
217
  var result;
275
218
  if (size === 4) result = buf.readFloatBE(offset);
276
219
  if (size === 8) result = buf.readDoubleBE(offset);
277
220
  return [result, size + 1];
278
221
  }
279
-
280
222
  function decodeExt(buf, offset, type, size, headerSize) {
281
223
  var toDecode = buf.slice(offset, offset + size);
282
224
  var decode = decodingTypes.get(type);
@@ -14,27 +14,25 @@ export function buildEncode(encodingTypes, options) {
14
14
  if (obj === false) return Buffer.from([0xc2]);
15
15
  if (obj instanceof Map) return encodeMap(obj, options, encode);
16
16
  if (typeof obj === 'string') return encodeString(obj, options);
17
-
18
17
  if (obj && (obj.readUInt32LE || obj instanceof Uint8Array)) {
19
18
  if (obj instanceof Uint8Array) {
20
19
  obj = Buffer.from(obj);
21
- } // weird hack to support Buffer
20
+ }
21
+ // weird hack to support Buffer
22
22
  // and Buffer-like objects
23
-
24
-
25
23
  return bl([getBufferHeader(obj.length), obj]);
26
24
  }
27
-
28
25
  if (Array.isArray(obj)) return bl().append([getHeader(obj.length, 0x90, 0xdc)].concat(_toConsumableArray(obj.map(encode))));
29
26
  if (_typeof(obj) === 'object') return encodeExt(obj, encodingTypes) || encodeObject(obj, options, encode);
30
27
  if (typeof obj === 'number') return encodeNumber(obj, options);
31
28
  throw new Error('not implemented yet');
32
29
  }
33
-
34
30
  return function (obj) {
35
31
  return encode(obj).slice();
36
32
  };
37
- } //
33
+ }
34
+
35
+ //
38
36
  //
39
37
  // === MENTAL SEPARATOR ===
40
38
  //
@@ -42,30 +40,24 @@ export function buildEncode(encodingTypes, options) {
42
40
 
43
41
  function encodeMap(map, options, encode) {
44
42
  var acc = [getHeader(map.size, 0x80, 0xde)];
45
-
46
43
  var keys = _toConsumableArray(map.keys());
47
-
48
44
  if (keys.every(function (item) {
49
45
  return typeof item === 'string';
50
46
  })) {
51
47
  console.warn('Map with string only keys will be deserialized as an object!');
52
48
  }
53
-
54
49
  keys.forEach(function (key) {
55
50
  acc.push(encode(key), encode(map.get(key)));
56
51
  });
57
52
  return bl(acc);
58
53
  }
59
-
60
54
  function encodeObject(obj, options, encode) {
61
55
  var keys = [];
62
-
63
56
  for (var key in obj) {
64
57
  if (obj.hasOwnProperty(key) && obj[key] !== undefined && typeof obj[key] !== 'function') {
65
58
  keys.push(key);
66
59
  }
67
60
  }
68
-
69
61
  var acc = [getHeader(keys.length, 0x80, 0xde)];
70
62
  if (options.sortKeys) keys.sort();
71
63
  keys.forEach(function (key) {
@@ -73,23 +65,22 @@ function encodeObject(obj, options, encode) {
73
65
  });
74
66
  return bl(acc);
75
67
  }
76
-
77
68
  function write64BitUint(buf, offset, num) {
78
69
  var lo = num % 4294967296;
79
70
  var hi = Math.floor(num / 4294967296);
80
71
  buf.writeUInt32BE(hi, offset + 0);
81
72
  buf.writeUInt32BE(lo, offset + 4);
82
73
  }
83
-
84
74
  function write64BitInt(buf, offset, num) {
85
75
  var negate = num < 0;
86
76
  num = Math.abs(num);
87
77
  write64BitUint(buf, offset, num);
88
78
  if (negate) negate64BitInt(buf, offset);
89
79
  }
90
-
91
80
  function negate64BitInt(buf, offset) {
92
- var i = offset + 8; // Optimization based on the fact that:
81
+ var i = offset + 8;
82
+
83
+ // Optimization based on the fact that:
93
84
  // buf[i] == 0x00 => (buf[i] ^ 0xff) + 1 = 0x100 = 0x00 + 1 curry
94
85
 
95
86
  while (i-- > offset) {
@@ -97,17 +88,13 @@ function negate64BitInt(buf, offset) {
97
88
  buf[i] = (buf[i] ^ 0xff) + 1;
98
89
  break;
99
90
  }
100
-
101
91
  while (i-- > offset) {
102
92
  buf[i] = buf[i] ^ 0xff;
103
93
  }
104
94
  }
105
-
106
95
  var fround = Math.fround;
107
-
108
96
  function encodeFloat(obj, forceFloat64) {
109
97
  var buf;
110
-
111
98
  if (forceFloat64 || !fround || fround(obj) !== obj) {
112
99
  buf = Buffer.allocUnsafe(9);
113
100
  buf[0] = 0xcb;
@@ -117,10 +104,8 @@ function encodeFloat(obj, forceFloat64) {
117
104
  buf[0] = 0xca;
118
105
  buf.writeFloatBE(obj, 1);
119
106
  }
120
-
121
107
  return buf;
122
108
  }
123
-
124
109
  function encodeExt(obj, encodingTypes) {
125
110
  var codec = encodingTypes.find(function (codec) {
126
111
  return codec.check(obj);
@@ -130,7 +115,6 @@ function encodeExt(obj, encodingTypes) {
130
115
  if (!encoded) return null;
131
116
  return bl([getExtHeader(encoded.length - 1), encoded]);
132
117
  }
133
-
134
118
  function getExtHeader(length) {
135
119
  if (length === 1) return Buffer.from([0xd4]);
136
120
  if (length === 2) return Buffer.from([0xd5]);
@@ -141,7 +125,6 @@ function getExtHeader(length) {
141
125
  if (length < 0x10000) return Buffer.from([0xc8, length >> 8, length & 0x00ff]);
142
126
  return Buffer.from([0xc9, length >> 24, length >> 16 & 0x000000ff, length >> 8 & 0x000000ff, length & 0x000000ff]);
143
127
  }
144
-
145
128
  function getHeader(length, tag1, tag2) {
146
129
  if (length < 16) return Buffer.from([tag1 | length]);
147
130
  var size = length < 0x10000 ? 2 : 4;
@@ -150,15 +133,12 @@ function getHeader(length, tag1, tag2) {
150
133
  buf.writeUIntBE(length, 1, size);
151
134
  return buf;
152
135
  }
153
-
154
136
  function encodeString(obj, options) {
155
137
  var len = Buffer.byteLength(obj);
156
138
  var buf;
157
-
158
139
  if (len < 32) {
159
140
  buf = Buffer.allocUnsafe(1 + len);
160
141
  buf[0] = 0xa0 | len;
161
-
162
142
  if (len > 0) {
163
143
  buf.write(obj, 1);
164
144
  }
@@ -179,13 +159,10 @@ function encodeString(obj, options) {
179
159
  buf.writeUInt32BE(len, 1);
180
160
  buf.write(obj, 5);
181
161
  }
182
-
183
162
  return buf;
184
163
  }
185
-
186
164
  function getBufferHeader(length) {
187
165
  var header;
188
-
189
166
  if (length <= 0xff) {
190
167
  header = Buffer.allocUnsafe(2);
191
168
  header[0] = 0xc4;
@@ -199,18 +176,14 @@ function getBufferHeader(length) {
199
176
  header[0] = 0xc6;
200
177
  header.writeUInt32BE(length, 1);
201
178
  }
202
-
203
179
  return header;
204
180
  }
205
-
206
181
  function encodeNumber(obj, options) {
207
182
  var buf;
208
183
  if (isFloat(obj)) return encodeFloat(obj, options.forceFloat64);
209
-
210
184
  if (Math.abs(obj) > 9007199254740991) {
211
185
  return encodeFloat(obj, true);
212
186
  }
213
-
214
187
  if (obj >= 0) {
215
188
  if (obj < 128) {
216
189
  return Buffer.from([obj]);
@@ -247,6 +220,5 @@ function encodeNumber(obj, options) {
247
220
  write64BitInt(buf, 1, obj);
248
221
  }
249
222
  }
250
-
251
223
  return buf;
252
224
  }
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
- import util from 'util'; // exports.IncompleteBufferError = IncompleteBufferError;
3
+ import util from 'util';
4
+
5
+ // exports.IncompleteBufferError = IncompleteBufferError;
4
6
 
5
7
  export function IncompleteBufferError(message) {
6
8
  Error.call(this); // super constructor
7
-
8
9
  if (Error.captureStackTrace) {
9
10
  Error.captureStackTrace(this, this.constructor); // super helper method to include stack trace in error object
10
11
  }
@@ -3,7 +3,6 @@
3
3
  import { Transform } from 'readable-stream';
4
4
  import inherits from 'inherits';
5
5
  import bl from 'bl';
6
-
7
6
  function Base(opts) {
8
7
  opts = opts || {};
9
8
  opts.objectMode = true;
@@ -11,64 +10,50 @@ function Base(opts) {
11
10
  Transform.call(this, opts);
12
11
  this._msgpack = opts.msgpack;
13
12
  }
14
-
15
13
  inherits(Base, Transform);
16
-
17
14
  function Encoder(opts) {
18
15
  if (!(this instanceof Encoder)) {
19
16
  opts = opts || {};
20
17
  opts.msgpack = this;
21
18
  return new Encoder(opts);
22
19
  }
23
-
24
20
  Base.call(this, opts);
25
21
  this._wrap = 'wrap' in opts && opts.wrap;
26
22
  }
27
-
28
23
  inherits(Encoder, Base);
29
-
30
24
  Encoder.prototype._transform = function (obj, enc, done) {
31
25
  var buf = null;
32
-
33
26
  try {
34
27
  buf = this._msgpack.encode(this._wrap ? obj.value : obj).slice(0);
35
28
  } catch (err) {
36
29
  this.emit('error', err);
37
30
  return done();
38
31
  }
39
-
40
32
  this.push(buf);
41
33
  done();
42
34
  };
43
-
44
35
  function Decoder(opts) {
45
36
  if (!(this instanceof Decoder)) {
46
37
  opts = opts || {};
47
38
  opts.msgpack = this;
48
39
  return new Decoder(opts);
49
40
  }
50
-
51
41
  Base.call(this, opts);
52
42
  this._chunks = bl();
53
43
  this._wrap = 'wrap' in opts && opts.wrap;
54
44
  }
55
-
56
45
  inherits(Decoder, Base);
57
-
58
46
  Decoder.prototype._transform = function (buf, enc, done) {
59
47
  if (buf) {
60
48
  this._chunks.append(buf);
61
49
  }
62
-
63
50
  try {
64
51
  var result = this._msgpack.decode(this._chunks);
65
-
66
52
  if (this._wrap) {
67
53
  result = {
68
54
  value: result
69
55
  };
70
56
  }
71
-
72
57
  this.push(result);
73
58
  } catch (err) {
74
59
  if (err instanceof this._msgpack.IncompleteBufferError) {
@@ -76,17 +61,14 @@ Decoder.prototype._transform = function (buf, enc, done) {
76
61
  } else {
77
62
  this.emit('error', err);
78
63
  }
79
-
80
64
  return;
81
65
  }
82
-
83
66
  if (this._chunks.length > 0) {
84
67
  this._transform(null, enc, done);
85
68
  } else {
86
69
  done();
87
70
  }
88
71
  };
89
-
90
72
  export default {
91
73
  Decoder: Decoder,
92
74
  Encoder: Encoder