ronds-metadata 1.2.9 → 1.2.10

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