jaelis-node 1.9.0 → 2.0.0

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.
Files changed (173) hide show
  1. package/README.md +147 -433
  2. package/bin/jaelis-node.js +79 -504
  3. package/lib/index.js +31 -2740
  4. package/lib/node.js +271 -0
  5. package/lib/rpc.js +315 -0
  6. package/lib/storage.js +198 -0
  7. package/lib/sync.js +366 -0
  8. package/package.json +19 -53
  9. package/config/default.json +0 -74
  10. package/config/mainnet.json +0 -30
  11. package/config/testnet.json +0 -26
  12. package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +0 -454
  13. package/lib/JAELIS-VM/lib/adapters/index.js +0 -411
  14. package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +0 -457
  15. package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +0 -1097
  16. package/lib/JAELIS-VM/lib/execution/engine.js +0 -1183
  17. package/lib/JAELIS-VM/lib/index.js +0 -440
  18. package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +0 -543
  19. package/lib/JAELIS-VM/lib/serialization/serializer.js +0 -819
  20. package/lib/JAELIS-VM/lib/state/state-manager.js +0 -1116
  21. package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +0 -1222
  22. package/lib/JAELIS-VM/lib/unified/cross-chain-deploy.js +0 -1678
  23. package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +0 -836
  24. package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +0 -1127
  25. package/lib/JAELIS-VM/lib/unified/index.js +0 -456
  26. package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +0 -1150
  27. package/lib/JAELIS-VM/lib/unified/unified-compiler.js +0 -1350
  28. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +0 -12
  29. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +0 -17
  30. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +0 -28
  31. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +0 -12
  32. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +0 -17
  33. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +0 -28
  34. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  35. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  36. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  37. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  38. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  39. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  40. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  41. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  42. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  43. package/lib/JAELIS-VM/node_modules/.package-lock.json +0 -127
  44. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +0 -1
  45. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
  46. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
  47. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
  48. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +0 -17
  49. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +0 -1
  50. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
  51. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
  52. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
  53. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +0 -17
  54. package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +0 -21
  55. package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +0 -5
  56. package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +0 -11
  57. package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +0 -60
  58. package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +0 -1
  59. package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +0 -50
  60. package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +0 -198
  61. package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +0 -21
  62. package/lib/JAELIS-VM/node_modules/cbor-x/README.md +0 -380
  63. package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +0 -11
  64. package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +0 -73
  65. package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +0 -11
  66. package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +0 -2
  67. package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +0 -1300
  68. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +0 -1244
  69. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +0 -1
  70. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +0 -2509
  71. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +0 -1
  72. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +0 -2
  73. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +0 -1
  74. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +0 -2508
  75. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +0 -1
  76. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +0 -2
  77. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +0 -1
  78. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +0 -2629
  79. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +0 -1
  80. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +0 -3343
  81. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +0 -1
  82. package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +0 -1
  83. package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +0 -1231
  84. package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +0 -79
  85. package/lib/JAELIS-VM/node_modules/cbor-x/index.js +0 -3
  86. package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +0 -85
  87. package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +0 -24
  88. package/lib/JAELIS-VM/node_modules/cbor-x/package.json +0 -94
  89. package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +0 -88
  90. package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +0 -61
  91. package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +0 -19
  92. package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +0 -201
  93. package/lib/JAELIS-VM/node_modules/detect-libc/README.md +0 -163
  94. package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +0 -14
  95. package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +0 -313
  96. package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +0 -39
  97. package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +0 -51
  98. package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +0 -24
  99. package/lib/JAELIS-VM/node_modules/detect-libc/package.json +0 -44
  100. package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +0 -21
  101. package/lib/JAELIS-VM/node_modules/msgpackr/README.md +0 -372
  102. package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +0 -11
  103. package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +0 -67
  104. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +0 -2407
  105. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -1
  106. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +0 -2
  107. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -1
  108. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +0 -2406
  109. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +0 -1
  110. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +0 -2
  111. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +0 -1
  112. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +0 -3320
  113. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +0 -1
  114. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +0 -4540
  115. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +0 -1
  116. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +0 -1250
  117. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -1
  118. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +0 -91
  119. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +0 -91
  120. package/lib/JAELIS-VM/node_modules/msgpackr/index.js +0 -5
  121. package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +0 -87
  122. package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +0 -25
  123. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +0 -1
  124. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +0 -1
  125. package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +0 -1141
  126. package/lib/JAELIS-VM/node_modules/msgpackr/package.json +0 -104
  127. package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +0 -88
  128. package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +0 -57
  129. package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +0 -815
  130. package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +0 -3
  131. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +0 -2
  132. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +0 -2
  133. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +0 -1221
  134. package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +0 -21
  135. package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +0 -5
  136. package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +0 -13
  137. package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +0 -63
  138. package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +0 -1
  139. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  140. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  141. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  142. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  143. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  144. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  145. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  146. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  147. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  148. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  149. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  150. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +0 -82
  151. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  152. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +0 -6
  153. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +0 -236
  154. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  155. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  156. package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +0 -50
  157. package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +0 -274
  158. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  159. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  160. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +0 -77
  161. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  162. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +0 -224
  163. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  164. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  165. package/lib/JAELIS-VM/package-lock.json +0 -284
  166. package/lib/JAELIS-VM/package.json +0 -38
  167. package/lib/JAELIS-VM/test/comprehensive.test.js +0 -267
  168. package/lib/JAELIS-VM/test/cross-chain-test.js +0 -470
  169. package/lib/JAELIS-VM/test/unified-vm-test.js +0 -459
  170. package/lib/JAELIS-VM/test/unified.test.js +0 -166
  171. package/lib/JAELIS-VM/test/vm.test.js +0 -599
  172. package/lib/settlement-server.js +0 -999
  173. package/lib/vm/index.js +0 -397
@@ -1,1250 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.msgpackr = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- var decoder;
8
- try {
9
- decoder = new TextDecoder();
10
- } catch(error) {}
11
- var src;
12
- var srcEnd;
13
- var position = 0;
14
- const EMPTY_ARRAY = [];
15
- var strings = EMPTY_ARRAY;
16
- var stringPosition = 0;
17
- var currentUnpackr = {};
18
- var currentStructures;
19
- var srcString;
20
- var srcStringStart = 0;
21
- var srcStringEnd = 0;
22
- var bundledStrings;
23
- var referenceMap;
24
- var currentExtensions = [];
25
- var dataView;
26
- var defaultOptions = {
27
- useRecords: false,
28
- mapsAsObjects: true
29
- };
30
- class C1Type {}
31
- const C1 = new C1Type();
32
- C1.name = 'MessagePack 0xC1';
33
- var sequentialMode = false;
34
- var inlineObjectReadThreshold = 2;
35
- var readStruct, onLoadedStructures, onSaveState;
36
- var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
37
- // no-eval build
38
- try {
39
- new BlockedFunction ('');
40
- } catch(error) {
41
- // if eval variants are not supported, do not create inline object readers ever
42
- inlineObjectReadThreshold = Infinity;
43
- }
44
-
45
- class Unpackr {
46
- constructor(options) {
47
- if (options) {
48
- if (options.useRecords === false && options.mapsAsObjects === undefined)
49
- options.mapsAsObjects = true;
50
- if (options.sequential && options.trusted !== false) {
51
- options.trusted = true;
52
- if (!options.structures && options.useRecords != false) {
53
- options.structures = [];
54
- if (!options.maxSharedStructures)
55
- options.maxSharedStructures = 0;
56
- }
57
- }
58
- if (options.structures)
59
- options.structures.sharedLength = options.structures.length;
60
- else if (options.getStructures) {
61
- (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
62
- options.structures.sharedLength = 0;
63
- }
64
- if (options.int64AsNumber) {
65
- options.int64AsType = 'number';
66
- }
67
- }
68
- Object.assign(this, options);
69
- }
70
- unpack(source, options) {
71
- if (src) {
72
- // re-entrant execution, save the state and restore it after we do this unpack
73
- return saveState(() => {
74
- clearSource();
75
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
76
- })
77
- }
78
- if (!source.buffer && source.constructor === ArrayBuffer)
79
- source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
80
- if (typeof options === 'object') {
81
- srcEnd = options.end || source.length;
82
- position = options.start || 0;
83
- } else {
84
- position = 0;
85
- srcEnd = options > -1 ? options : source.length;
86
- }
87
- stringPosition = 0;
88
- srcStringEnd = 0;
89
- srcString = null;
90
- strings = EMPTY_ARRAY;
91
- bundledStrings = null;
92
- src = source;
93
- // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
94
- // technique for getting data from a database where it can be copied into an existing buffer instead of creating
95
- // new ones
96
- try {
97
- dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
98
- } catch(error) {
99
- // if it doesn't have a buffer, maybe it is the wrong type of object
100
- src = null;
101
- if (source instanceof Uint8Array)
102
- throw error
103
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
104
- }
105
- if (this instanceof Unpackr) {
106
- currentUnpackr = this;
107
- if (this.structures) {
108
- currentStructures = this.structures;
109
- return checkedRead(options)
110
- } else if (!currentStructures || currentStructures.length > 0) {
111
- currentStructures = [];
112
- }
113
- } else {
114
- currentUnpackr = defaultOptions;
115
- if (!currentStructures || currentStructures.length > 0)
116
- currentStructures = [];
117
- }
118
- return checkedRead(options)
119
- }
120
- unpackMultiple(source, forEach) {
121
- let values, lastPosition = 0;
122
- try {
123
- sequentialMode = true;
124
- let size = source.length;
125
- let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
126
- if (forEach) {
127
- if (forEach(value, lastPosition, position) === false) return;
128
- while(position < size) {
129
- lastPosition = position;
130
- if (forEach(checkedRead(), lastPosition, position) === false) {
131
- return
132
- }
133
- }
134
- }
135
- else {
136
- values = [ value ];
137
- while(position < size) {
138
- lastPosition = position;
139
- values.push(checkedRead());
140
- }
141
- return values
142
- }
143
- } catch(error) {
144
- error.lastPosition = lastPosition;
145
- error.values = values;
146
- throw error
147
- } finally {
148
- sequentialMode = false;
149
- clearSource();
150
- }
151
- }
152
- _mergeStructures(loadedStructures, existingStructures) {
153
- if (onLoadedStructures)
154
- loadedStructures = onLoadedStructures.call(this, loadedStructures);
155
- loadedStructures = loadedStructures || [];
156
- if (Object.isFrozen(loadedStructures))
157
- loadedStructures = loadedStructures.map(structure => structure.slice(0));
158
- for (let i = 0, l = loadedStructures.length; i < l; i++) {
159
- let structure = loadedStructures[i];
160
- if (structure) {
161
- structure.isShared = true;
162
- if (i >= 32)
163
- structure.highByte = (i - 32) >> 5;
164
- }
165
- }
166
- loadedStructures.sharedLength = loadedStructures.length;
167
- for (let id in existingStructures || []) {
168
- if (id >= 0) {
169
- let structure = loadedStructures[id];
170
- let existing = existingStructures[id];
171
- if (existing) {
172
- if (structure)
173
- (loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure;
174
- loadedStructures[id] = existing;
175
- }
176
- }
177
- }
178
- return this.structures = loadedStructures
179
- }
180
- decode(source, options) {
181
- return this.unpack(source, options)
182
- }
183
- }
184
- function getPosition() {
185
- return position
186
- }
187
- function checkedRead(options) {
188
- try {
189
- if (!currentUnpackr.trusted && !sequentialMode) {
190
- let sharedLength = currentStructures.sharedLength || 0;
191
- if (sharedLength < currentStructures.length)
192
- currentStructures.length = sharedLength;
193
- }
194
- let result;
195
- if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
196
- result = readStruct(src, position, srcEnd, currentUnpackr);
197
- src = null; // dispose of this so that recursive unpack calls don't save state
198
- if (!(options && options.lazy) && result)
199
- result = result.toJSON();
200
- position = srcEnd;
201
- } else
202
- result = read();
203
- if (bundledStrings) { // bundled strings to skip past
204
- position = bundledStrings.postBundlePosition;
205
- bundledStrings = null;
206
- }
207
- if (sequentialMode)
208
- // we only need to restore the structures if there was an error, but if we completed a read,
209
- // we can clear this out and keep the structures we read
210
- currentStructures.restoreStructures = null;
211
-
212
- if (position == srcEnd) {
213
- // finished reading this source, cleanup references
214
- if (currentStructures && currentStructures.restoreStructures)
215
- restoreStructures();
216
- currentStructures = null;
217
- src = null;
218
- if (referenceMap)
219
- referenceMap = null;
220
- } else if (position > srcEnd) {
221
- // over read
222
- throw new Error('Unexpected end of MessagePack data')
223
- } else if (!sequentialMode) {
224
- let jsonView;
225
- try {
226
- jsonView = JSON.stringify(result, (_, value) => typeof value === "bigint" ? `${value}n` : value).slice(0, 100);
227
- } catch(error) {
228
- jsonView = '(JSON view not available ' + error + ')';
229
- }
230
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
231
- }
232
- // else more to read, but we are reading sequentially, so don't clear source yet
233
- return result
234
- } catch(error) {
235
- if (currentStructures && currentStructures.restoreStructures)
236
- restoreStructures();
237
- clearSource();
238
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
239
- error.incomplete = true;
240
- }
241
- throw error
242
- }
243
- }
244
-
245
- function restoreStructures() {
246
- for (let id in currentStructures.restoreStructures) {
247
- currentStructures[id] = currentStructures.restoreStructures[id];
248
- }
249
- currentStructures.restoreStructures = null;
250
- }
251
-
252
- function read() {
253
- let token = src[position++];
254
- if (token < 0xa0) {
255
- if (token < 0x80) {
256
- if (token < 0x40)
257
- return token
258
- else {
259
- let structure = currentStructures[token & 0x3f] ||
260
- currentUnpackr.getStructures && loadStructures()[token & 0x3f];
261
- if (structure) {
262
- if (!structure.read) {
263
- structure.read = createStructureReader(structure, token & 0x3f);
264
- }
265
- return structure.read()
266
- } else
267
- return token
268
- }
269
- } else if (token < 0x90) {
270
- // map
271
- token -= 0x80;
272
- if (currentUnpackr.mapsAsObjects) {
273
- let object = {};
274
- for (let i = 0; i < token; i++) {
275
- let key = readKey();
276
- if (key === '__proto__')
277
- key = '__proto_';
278
- object[key] = read();
279
- }
280
- return object
281
- } else {
282
- let map = new Map();
283
- for (let i = 0; i < token; i++) {
284
- map.set(read(), read());
285
- }
286
- return map
287
- }
288
- } else {
289
- token -= 0x90;
290
- let array = new Array(token);
291
- for (let i = 0; i < token; i++) {
292
- array[i] = read();
293
- }
294
- if (currentUnpackr.freezeData)
295
- return Object.freeze(array)
296
- return array
297
- }
298
- } else if (token < 0xc0) {
299
- // fixstr
300
- let length = token - 0xa0;
301
- if (srcStringEnd >= position) {
302
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
303
- }
304
- if (srcStringEnd == 0 && srcEnd < 140) {
305
- // for small blocks, avoiding the overhead of the extract call is helpful
306
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
307
- if (string != null)
308
- return string
309
- }
310
- return readFixedString(length)
311
- } else {
312
- let value;
313
- switch (token) {
314
- case 0xc0: return null
315
- case 0xc1:
316
- if (bundledStrings) {
317
- value = read(); // followed by the length of the string in characters (not bytes!)
318
- if (value > 0)
319
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
320
- else
321
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
322
- }
323
- return C1; // "never-used", return special object to denote that
324
- case 0xc2: return false
325
- case 0xc3: return true
326
- case 0xc4:
327
- // bin 8
328
- value = src[position++];
329
- if (value === undefined)
330
- throw new Error('Unexpected end of buffer')
331
- return readBin(value)
332
- case 0xc5:
333
- // bin 16
334
- value = dataView.getUint16(position);
335
- position += 2;
336
- return readBin(value)
337
- case 0xc6:
338
- // bin 32
339
- value = dataView.getUint32(position);
340
- position += 4;
341
- return readBin(value)
342
- case 0xc7:
343
- // ext 8
344
- return readExt(src[position++])
345
- case 0xc8:
346
- // ext 16
347
- value = dataView.getUint16(position);
348
- position += 2;
349
- return readExt(value)
350
- case 0xc9:
351
- // ext 32
352
- value = dataView.getUint32(position);
353
- position += 4;
354
- return readExt(value)
355
- case 0xca:
356
- value = dataView.getFloat32(position);
357
- if (currentUnpackr.useFloat32 > 2) {
358
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
359
- let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
360
- position += 4;
361
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
362
- }
363
- position += 4;
364
- return value
365
- case 0xcb:
366
- value = dataView.getFloat64(position);
367
- position += 8;
368
- return value
369
- // uint handlers
370
- case 0xcc:
371
- return src[position++]
372
- case 0xcd:
373
- value = dataView.getUint16(position);
374
- position += 2;
375
- return value
376
- case 0xce:
377
- value = dataView.getUint32(position);
378
- position += 4;
379
- return value
380
- case 0xcf:
381
- if (currentUnpackr.int64AsType === 'number') {
382
- value = dataView.getUint32(position) * 0x100000000;
383
- value += dataView.getUint32(position + 4);
384
- } else if (currentUnpackr.int64AsType === 'string') {
385
- value = dataView.getBigUint64(position).toString();
386
- } else if (currentUnpackr.int64AsType === 'auto') {
387
- value = dataView.getBigUint64(position);
388
- if (value<=BigInt(2)<<BigInt(52)) value=Number(value);
389
- } else
390
- value = dataView.getBigUint64(position);
391
- position += 8;
392
- return value
393
-
394
- // int handlers
395
- case 0xd0:
396
- return dataView.getInt8(position++)
397
- case 0xd1:
398
- value = dataView.getInt16(position);
399
- position += 2;
400
- return value
401
- case 0xd2:
402
- value = dataView.getInt32(position);
403
- position += 4;
404
- return value
405
- case 0xd3:
406
- if (currentUnpackr.int64AsType === 'number') {
407
- value = dataView.getInt32(position) * 0x100000000;
408
- value += dataView.getUint32(position + 4);
409
- } else if (currentUnpackr.int64AsType === 'string') {
410
- value = dataView.getBigInt64(position).toString();
411
- } else if (currentUnpackr.int64AsType === 'auto') {
412
- value = dataView.getBigInt64(position);
413
- if (value>=BigInt(-2)<<BigInt(52)&&value<=BigInt(2)<<BigInt(52)) value=Number(value);
414
- } else
415
- value = dataView.getBigInt64(position);
416
- position += 8;
417
- return value
418
-
419
- case 0xd4:
420
- // fixext 1
421
- value = src[position++];
422
- if (value == 0x72) {
423
- return recordDefinition(src[position++] & 0x3f)
424
- } else {
425
- let extension = currentExtensions[value];
426
- if (extension) {
427
- if (extension.read) {
428
- position++; // skip filler byte
429
- return extension.read(read())
430
- } else if (extension.noBuffer) {
431
- position++; // skip filler byte
432
- return extension()
433
- } else
434
- return extension(src.subarray(position, ++position))
435
- } else
436
- throw new Error('Unknown extension ' + value)
437
- }
438
- case 0xd5:
439
- // fixext 2
440
- value = src[position];
441
- if (value == 0x72) {
442
- position++;
443
- return recordDefinition(src[position++] & 0x3f, src[position++])
444
- } else
445
- return readExt(2)
446
- case 0xd6:
447
- // fixext 4
448
- return readExt(4)
449
- case 0xd7:
450
- // fixext 8
451
- return readExt(8)
452
- case 0xd8:
453
- // fixext 16
454
- return readExt(16)
455
- case 0xd9:
456
- // str 8
457
- value = src[position++];
458
- if (srcStringEnd >= position) {
459
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
460
- }
461
- return readString8(value)
462
- case 0xda:
463
- // str 16
464
- value = dataView.getUint16(position);
465
- position += 2;
466
- if (srcStringEnd >= position) {
467
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
468
- }
469
- return readString16(value)
470
- case 0xdb:
471
- // str 32
472
- value = dataView.getUint32(position);
473
- position += 4;
474
- if (srcStringEnd >= position) {
475
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
476
- }
477
- return readString32(value)
478
- case 0xdc:
479
- // array 16
480
- value = dataView.getUint16(position);
481
- position += 2;
482
- return readArray(value)
483
- case 0xdd:
484
- // array 32
485
- value = dataView.getUint32(position);
486
- position += 4;
487
- return readArray(value)
488
- case 0xde:
489
- // map 16
490
- value = dataView.getUint16(position);
491
- position += 2;
492
- return readMap(value)
493
- case 0xdf:
494
- // map 32
495
- value = dataView.getUint32(position);
496
- position += 4;
497
- return readMap(value)
498
- default: // negative int
499
- if (token >= 0xe0)
500
- return token - 0x100
501
- if (token === undefined) {
502
- let error = new Error('Unexpected end of MessagePack data');
503
- error.incomplete = true;
504
- throw error
505
- }
506
- throw new Error('Unknown MessagePack token ' + token)
507
-
508
- }
509
- }
510
- }
511
- const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
512
- function createStructureReader(structure, firstId) {
513
- function readObject() {
514
- // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
515
- if (readObject.count++ > inlineObjectReadThreshold) {
516
- let readObject = structure.read = (new BlockedFunction ('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
517
- '({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
518
- if (structure.highByte === 0)
519
- structure.read = createSecondByteReader(firstId, structure.read);
520
- return readObject() // second byte is already read, if there is one so immediately read object
521
- }
522
- let object = {};
523
- for (let i = 0, l = structure.length; i < l; i++) {
524
- let key = structure[i];
525
- if (key === '__proto__')
526
- key = '__proto_';
527
- object[key] = read();
528
- }
529
- if (currentUnpackr.freezeData)
530
- return Object.freeze(object);
531
- return object
532
- }
533
- readObject.count = 0;
534
- if (structure.highByte === 0) {
535
- return createSecondByteReader(firstId, readObject)
536
- }
537
- return readObject
538
- }
539
-
540
- const createSecondByteReader = (firstId, read0) => {
541
- return function() {
542
- let highByte = src[position++];
543
- if (highByte === 0)
544
- return read0()
545
- let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
546
- let structure = currentStructures[id] || loadStructures()[id];
547
- if (!structure) {
548
- throw new Error('Record id is not defined for ' + id)
549
- }
550
- if (!structure.read)
551
- structure.read = createStructureReader(structure, firstId);
552
- return structure.read()
553
- }
554
- };
555
-
556
- function loadStructures() {
557
- let loadedStructures = saveState(() => {
558
- // save the state in case getStructures modifies our buffer
559
- src = null;
560
- return currentUnpackr.getStructures()
561
- });
562
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
563
- }
564
-
565
- var readFixedString = readStringJS;
566
- var readString8 = readStringJS;
567
- var readString16 = readStringJS;
568
- var readString32 = readStringJS;
569
- exports.isNativeAccelerationEnabled = false;
570
-
571
- function setExtractor(extractStrings) {
572
- exports.isNativeAccelerationEnabled = true;
573
- readFixedString = readString(1);
574
- readString8 = readString(2);
575
- readString16 = readString(3);
576
- readString32 = readString(5);
577
- function readString(headerLength) {
578
- return function readString(length) {
579
- let string = strings[stringPosition++];
580
- if (string == null) {
581
- if (bundledStrings)
582
- return readStringJS(length)
583
- let byteOffset = src.byteOffset;
584
- let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
585
- if (typeof extraction == 'string') {
586
- string = extraction;
587
- strings = EMPTY_ARRAY;
588
- } else {
589
- strings = extraction;
590
- stringPosition = 1;
591
- srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
592
- string = strings[0];
593
- if (string === undefined)
594
- throw new Error('Unexpected end of buffer')
595
- }
596
- }
597
- let srcStringLength = string.length;
598
- if (srcStringLength <= length) {
599
- position += length;
600
- return string
601
- }
602
- srcString = string;
603
- srcStringStart = position;
604
- srcStringEnd = position + srcStringLength;
605
- position += length;
606
- return string.slice(0, length) // we know we just want the beginning
607
- }
608
- }
609
- }
610
- function readStringJS(length) {
611
- let result;
612
- if (length < 16) {
613
- if (result = shortStringInJS(length))
614
- return result
615
- }
616
- if (length > 64 && decoder)
617
- return decoder.decode(src.subarray(position, position += length))
618
- const end = position + length;
619
- const units = [];
620
- result = '';
621
- while (position < end) {
622
- const byte1 = src[position++];
623
- if ((byte1 & 0x80) === 0) {
624
- // 1 byte
625
- units.push(byte1);
626
- } else if ((byte1 & 0xe0) === 0xc0) {
627
- // 2 bytes
628
- const byte2 = src[position++] & 0x3f;
629
- units.push(((byte1 & 0x1f) << 6) | byte2);
630
- } else if ((byte1 & 0xf0) === 0xe0) {
631
- // 3 bytes
632
- const byte2 = src[position++] & 0x3f;
633
- const byte3 = src[position++] & 0x3f;
634
- units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
635
- } else if ((byte1 & 0xf8) === 0xf0) {
636
- // 4 bytes
637
- const byte2 = src[position++] & 0x3f;
638
- const byte3 = src[position++] & 0x3f;
639
- const byte4 = src[position++] & 0x3f;
640
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
641
- if (unit > 0xffff) {
642
- unit -= 0x10000;
643
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
644
- unit = 0xdc00 | (unit & 0x3ff);
645
- }
646
- units.push(unit);
647
- } else {
648
- units.push(byte1);
649
- }
650
-
651
- if (units.length >= 0x1000) {
652
- result += fromCharCode.apply(String, units);
653
- units.length = 0;
654
- }
655
- }
656
-
657
- if (units.length > 0) {
658
- result += fromCharCode.apply(String, units);
659
- }
660
-
661
- return result
662
- }
663
- function readString(source, start, length) {
664
- let existingSrc = src;
665
- src = source;
666
- position = start;
667
- try {
668
- return readStringJS(length);
669
- } finally {
670
- src = existingSrc;
671
- }
672
- }
673
-
674
- function readArray(length) {
675
- let array = new Array(length);
676
- for (let i = 0; i < length; i++) {
677
- array[i] = read();
678
- }
679
- if (currentUnpackr.freezeData)
680
- return Object.freeze(array)
681
- return array
682
- }
683
-
684
- function readMap(length) {
685
- if (currentUnpackr.mapsAsObjects) {
686
- let object = {};
687
- for (let i = 0; i < length; i++) {
688
- let key = readKey();
689
- if (key === '__proto__')
690
- key = '__proto_';
691
- object[key] = read();
692
- }
693
- return object
694
- } else {
695
- let map = new Map();
696
- for (let i = 0; i < length; i++) {
697
- map.set(read(), read());
698
- }
699
- return map
700
- }
701
- }
702
-
703
- var fromCharCode = String.fromCharCode;
704
- function longStringInJS(length) {
705
- let start = position;
706
- let bytes = new Array(length);
707
- for (let i = 0; i < length; i++) {
708
- const byte = src[position++];
709
- if ((byte & 0x80) > 0) {
710
- position = start;
711
- return
712
- }
713
- bytes[i] = byte;
714
- }
715
- return fromCharCode.apply(String, bytes)
716
- }
717
- function shortStringInJS(length) {
718
- if (length < 4) {
719
- if (length < 2) {
720
- if (length === 0)
721
- return ''
722
- else {
723
- let a = src[position++];
724
- if ((a & 0x80) > 1) {
725
- position -= 1;
726
- return
727
- }
728
- return fromCharCode(a)
729
- }
730
- } else {
731
- let a = src[position++];
732
- let b = src[position++];
733
- if ((a & 0x80) > 0 || (b & 0x80) > 0) {
734
- position -= 2;
735
- return
736
- }
737
- if (length < 3)
738
- return fromCharCode(a, b)
739
- let c = src[position++];
740
- if ((c & 0x80) > 0) {
741
- position -= 3;
742
- return
743
- }
744
- return fromCharCode(a, b, c)
745
- }
746
- } else {
747
- let a = src[position++];
748
- let b = src[position++];
749
- let c = src[position++];
750
- let d = src[position++];
751
- if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
752
- position -= 4;
753
- return
754
- }
755
- if (length < 6) {
756
- if (length === 4)
757
- return fromCharCode(a, b, c, d)
758
- else {
759
- let e = src[position++];
760
- if ((e & 0x80) > 0) {
761
- position -= 5;
762
- return
763
- }
764
- return fromCharCode(a, b, c, d, e)
765
- }
766
- } else if (length < 8) {
767
- let e = src[position++];
768
- let f = src[position++];
769
- if ((e & 0x80) > 0 || (f & 0x80) > 0) {
770
- position -= 6;
771
- return
772
- }
773
- if (length < 7)
774
- return fromCharCode(a, b, c, d, e, f)
775
- let g = src[position++];
776
- if ((g & 0x80) > 0) {
777
- position -= 7;
778
- return
779
- }
780
- return fromCharCode(a, b, c, d, e, f, g)
781
- } else {
782
- let e = src[position++];
783
- let f = src[position++];
784
- let g = src[position++];
785
- let h = src[position++];
786
- if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
787
- position -= 8;
788
- return
789
- }
790
- if (length < 10) {
791
- if (length === 8)
792
- return fromCharCode(a, b, c, d, e, f, g, h)
793
- else {
794
- let i = src[position++];
795
- if ((i & 0x80) > 0) {
796
- position -= 9;
797
- return
798
- }
799
- return fromCharCode(a, b, c, d, e, f, g, h, i)
800
- }
801
- } else if (length < 12) {
802
- let i = src[position++];
803
- let j = src[position++];
804
- if ((i & 0x80) > 0 || (j & 0x80) > 0) {
805
- position -= 10;
806
- return
807
- }
808
- if (length < 11)
809
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
810
- let k = src[position++];
811
- if ((k & 0x80) > 0) {
812
- position -= 11;
813
- return
814
- }
815
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
816
- } else {
817
- let i = src[position++];
818
- let j = src[position++];
819
- let k = src[position++];
820
- let l = src[position++];
821
- if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
822
- position -= 12;
823
- return
824
- }
825
- if (length < 14) {
826
- if (length === 12)
827
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
828
- else {
829
- let m = src[position++];
830
- if ((m & 0x80) > 0) {
831
- position -= 13;
832
- return
833
- }
834
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
835
- }
836
- } else {
837
- let m = src[position++];
838
- let n = src[position++];
839
- if ((m & 0x80) > 0 || (n & 0x80) > 0) {
840
- position -= 14;
841
- return
842
- }
843
- if (length < 15)
844
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
845
- let o = src[position++];
846
- if ((o & 0x80) > 0) {
847
- position -= 15;
848
- return
849
- }
850
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
851
- }
852
- }
853
- }
854
- }
855
- }
856
-
857
- function readOnlyJSString() {
858
- let token = src[position++];
859
- let length;
860
- if (token < 0xc0) {
861
- // fixstr
862
- length = token - 0xa0;
863
- } else {
864
- switch(token) {
865
- case 0xd9:
866
- // str 8
867
- length = src[position++];
868
- break
869
- case 0xda:
870
- // str 16
871
- length = dataView.getUint16(position);
872
- position += 2;
873
- break
874
- case 0xdb:
875
- // str 32
876
- length = dataView.getUint32(position);
877
- position += 4;
878
- break
879
- default:
880
- throw new Error('Expected string')
881
- }
882
- }
883
- return readStringJS(length)
884
- }
885
-
886
-
887
- function readBin(length) {
888
- return currentUnpackr.copyBuffers ?
889
- // specifically use the copying slice (not the node one)
890
- Uint8Array.prototype.slice.call(src, position, position += length) :
891
- src.subarray(position, position += length)
892
- }
893
- function readExt(length) {
894
- let type = src[position++];
895
- if (currentExtensions[type]) {
896
- let end;
897
- return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
898
- position = readPosition;
899
- try {
900
- return read();
901
- } finally {
902
- position = end;
903
- }
904
- })
905
- }
906
- else
907
- throw new Error('Unknown extension type ' + type)
908
- }
909
-
910
- var keyCache = new Array(4096);
911
- function readKey() {
912
- let length = src[position++];
913
- if (length >= 0xa0 && length < 0xc0) {
914
- // fixstr, potentially use key cache
915
- length = length - 0xa0;
916
- if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
917
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
918
- else if (!(srcStringEnd == 0 && srcEnd < 180))
919
- return readFixedString(length)
920
- } else { // not cacheable, go back and do a standard read
921
- position--;
922
- return asSafeString(read())
923
- }
924
- let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
925
- let entry = keyCache[key];
926
- let checkPosition = position;
927
- let end = position + length - 3;
928
- let chunk;
929
- let i = 0;
930
- if (entry && entry.bytes == length) {
931
- while (checkPosition < end) {
932
- chunk = dataView.getUint32(checkPosition);
933
- if (chunk != entry[i++]) {
934
- checkPosition = 0x70000000;
935
- break
936
- }
937
- checkPosition += 4;
938
- }
939
- end += 3;
940
- while (checkPosition < end) {
941
- chunk = src[checkPosition++];
942
- if (chunk != entry[i++]) {
943
- checkPosition = 0x70000000;
944
- break
945
- }
946
- }
947
- if (checkPosition === end) {
948
- position = checkPosition;
949
- return entry.string
950
- }
951
- end -= 3;
952
- checkPosition = position;
953
- }
954
- entry = [];
955
- keyCache[key] = entry;
956
- entry.bytes = length;
957
- while (checkPosition < end) {
958
- chunk = dataView.getUint32(checkPosition);
959
- entry.push(chunk);
960
- checkPosition += 4;
961
- }
962
- end += 3;
963
- while (checkPosition < end) {
964
- chunk = src[checkPosition++];
965
- entry.push(chunk);
966
- }
967
- // for small blocks, avoiding the overhead of the extract call is helpful
968
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
969
- if (string != null)
970
- return entry.string = string
971
- return entry.string = readFixedString(length)
972
- }
973
-
974
- function asSafeString(property) {
975
- // protect against expensive (DoS) string conversions
976
- if (typeof property === 'string') return property;
977
- if (typeof property === 'number' || typeof property === 'boolean' || typeof property === 'bigint') return property.toString();
978
- if (property == null) return property + '';
979
- if (currentUnpackr.allowArraysInMapKeys && Array.isArray(property) && property.flat().every(item => ['string', 'number', 'boolean', 'bigint'].includes(typeof item))) {
980
- return property.flat().toString();
981
- }
982
- throw new Error(`Invalid property type for record: ${typeof property}`);
983
- }
984
- // the registration of the record definition extension (as "r")
985
- const recordDefinition = (id, highByte) => {
986
- let structure = read().map(asSafeString); // ensure that all keys are strings and
987
- // that the array is mutable
988
- let firstByte = id;
989
- if (highByte !== undefined) {
990
- id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
991
- structure.highByte = highByte;
992
- }
993
- let existingStructure = currentStructures[id];
994
- // If it is a shared structure, we need to restore any changes after reading.
995
- // Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
996
- // to the state prior to an incomplete read in order to properly resume.
997
- if (existingStructure && (existingStructure.isShared || sequentialMode)) {
998
- (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
999
- }
1000
- currentStructures[id] = structure;
1001
- structure.read = createStructureReader(structure, firstByte);
1002
- return structure.read()
1003
- };
1004
- currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1005
- currentExtensions[0].noBuffer = true;
1006
-
1007
- currentExtensions[0x42] = data => {
1008
- let headLength = (data.byteLength % 8) || 8;
1009
- let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
1010
- for (let i = 1; i < headLength; i++) {
1011
- head <<= BigInt(8);
1012
- head += BigInt(data[i]);
1013
- }
1014
- if (data.byteLength !== headLength) {
1015
- let view = new DataView(data.buffer, data.byteOffset, data.byteLength);
1016
- let decode = (start, end) => {
1017
- let length = end - start;
1018
- if (length <= 40) {
1019
- let out = view.getBigUint64(start);
1020
- for (let i = start + 8; i < end; i += 8) {
1021
- out <<= BigInt(64n);
1022
- out |= view.getBigUint64(i);
1023
- }
1024
- return out
1025
- }
1026
- // if (length === 8) return view.getBigUint64(start)
1027
- let middle = start + (length >> 4 << 3);
1028
- let left = decode(start, middle);
1029
- let right = decode(middle, end);
1030
- return (left << BigInt((end - middle) * 8)) | right
1031
- };
1032
- head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1033
- }
1034
- return head
1035
- };
1036
-
1037
- let errors = {
1038
- Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
1039
- };
1040
- currentExtensions[0x65] = () => {
1041
- let data = read();
1042
- if (!errors[data[0]]) {
1043
- let error = Error(data[1], { cause: data[2] });
1044
- error.name = data[0];
1045
- return error
1046
- }
1047
- return errors[data[0]](data[1], { cause: data[2] })
1048
- };
1049
-
1050
- currentExtensions[0x69] = (data) => {
1051
- // id extension (for structured clones)
1052
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1053
- let id = dataView.getUint32(position - 4);
1054
- if (!referenceMap)
1055
- referenceMap = new Map();
1056
- let token = src[position];
1057
- let target;
1058
- // TODO: handle any other types that can cycle and make the code more robust if there are other extensions
1059
- if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
1060
- target = [];
1061
- else if (token >= 0x80 && token < 0x90 || token == 0xde || token == 0xdf)
1062
- target = new Map();
1063
- else if ((token >= 0xc7 && token <= 0xc9 || token >= 0xd4 && token <= 0xd8) && src[position + 1] === 0x73)
1064
- target = new Set();
1065
- else
1066
- target = {};
1067
-
1068
- let refEntry = { target }; // a placeholder object
1069
- referenceMap.set(id, refEntry);
1070
- let targetProperties = read(); // read the next value as the target object to id
1071
- if (!refEntry.used) {
1072
- // no cycle, can just use the returned read object
1073
- return refEntry.target = targetProperties // replace the placeholder with the real one
1074
- } else {
1075
- // there is a cycle, so we have to assign properties to original target
1076
- Object.assign(target, targetProperties);
1077
- }
1078
-
1079
- // copy over map/set entries if we're able to
1080
- if (target instanceof Map)
1081
- for (let [k, v] of targetProperties.entries()) target.set(k, v);
1082
- if (target instanceof Set)
1083
- for (let i of Array.from(targetProperties)) target.add(i);
1084
- return target
1085
- };
1086
-
1087
- currentExtensions[0x70] = (data) => {
1088
- // pointer extension (for structured clones)
1089
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1090
- let id = dataView.getUint32(position - 4);
1091
- let refEntry = referenceMap.get(id);
1092
- refEntry.used = true;
1093
- return refEntry.target
1094
- };
1095
-
1096
- currentExtensions[0x73] = () => new Set(read());
1097
-
1098
- const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
1099
-
1100
- let glbl = typeof globalThis === 'object' ? globalThis : window;
1101
- currentExtensions[0x74] = (data) => {
1102
- let typeCode = data[0];
1103
- // we always have to slice to get a new ArrayBuffer that is aligned
1104
- let buffer = Uint8Array.prototype.slice.call(data, 1).buffer;
1105
-
1106
- let typedArrayName = typedArrays[typeCode];
1107
- if (!typedArrayName) {
1108
- if (typeCode === 16) return buffer
1109
- if (typeCode === 17) return new DataView(buffer)
1110
- throw new Error('Could not find typed array for code ' + typeCode)
1111
- }
1112
- return new glbl[typedArrayName](buffer)
1113
- };
1114
- currentExtensions[0x78] = () => {
1115
- let data = read();
1116
- return new RegExp(data[0], data[1])
1117
- };
1118
- const TEMP_BUNDLE = [];
1119
- currentExtensions[0x62] = (data) => {
1120
- let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
1121
- let dataPosition = position;
1122
- position += dataSize - data.length;
1123
- bundledStrings = TEMP_BUNDLE;
1124
- bundledStrings = [readOnlyJSString(), readOnlyJSString()];
1125
- bundledStrings.position0 = 0;
1126
- bundledStrings.position1 = 0;
1127
- bundledStrings.postBundlePosition = position;
1128
- position = dataPosition;
1129
- return read()
1130
- };
1131
-
1132
- currentExtensions[0xff] = (data) => {
1133
- // 32-bit date extension
1134
- if (data.length == 4)
1135
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1136
- else if (data.length == 8)
1137
- return new Date(
1138
- ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1139
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1140
- else if (data.length == 12)
1141
- return new Date(
1142
- ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1143
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1144
- else
1145
- return new Date('invalid')
1146
- };
1147
- // registration of bulk record definition?
1148
- // currentExtensions[0x52] = () =>
1149
-
1150
- function saveState(callback) {
1151
- if (onSaveState)
1152
- onSaveState();
1153
- let savedSrcEnd = srcEnd;
1154
- let savedPosition = position;
1155
- let savedStringPosition = stringPosition;
1156
- let savedSrcStringStart = srcStringStart;
1157
- let savedSrcStringEnd = srcStringEnd;
1158
- let savedSrcString = srcString;
1159
- let savedStrings = strings;
1160
- let savedReferenceMap = referenceMap;
1161
- let savedBundledStrings = bundledStrings;
1162
-
1163
- // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
1164
- let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
1165
- let savedStructures = currentStructures;
1166
- let savedStructuresContents = currentStructures.slice(0, currentStructures.length);
1167
- let savedPackr = currentUnpackr;
1168
- let savedSequentialMode = sequentialMode;
1169
- let value = callback();
1170
- srcEnd = savedSrcEnd;
1171
- position = savedPosition;
1172
- stringPosition = savedStringPosition;
1173
- srcStringStart = savedSrcStringStart;
1174
- srcStringEnd = savedSrcStringEnd;
1175
- srcString = savedSrcString;
1176
- strings = savedStrings;
1177
- referenceMap = savedReferenceMap;
1178
- bundledStrings = savedBundledStrings;
1179
- src = savedSrc;
1180
- sequentialMode = savedSequentialMode;
1181
- currentStructures = savedStructures;
1182
- currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1183
- currentUnpackr = savedPackr;
1184
- dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1185
- return value
1186
- }
1187
- function clearSource() {
1188
- src = null;
1189
- referenceMap = null;
1190
- currentStructures = null;
1191
- }
1192
-
1193
- function addExtension(extension) {
1194
- if (extension.unpack)
1195
- currentExtensions[extension.type] = extension.unpack;
1196
- else
1197
- currentExtensions[extension.type] = extension;
1198
- }
1199
-
1200
- const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1201
- for (let i = 0; i < 256; i++) {
1202
- mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
1203
- }
1204
- const Decoder = Unpackr;
1205
- var defaultUnpackr = new Unpackr({ useRecords: false });
1206
- const unpack = defaultUnpackr.unpack;
1207
- const unpackMultiple = defaultUnpackr.unpackMultiple;
1208
- const decode = defaultUnpackr.unpack;
1209
- const FLOAT32_OPTIONS = {
1210
- NEVER: 0,
1211
- ALWAYS: 1,
1212
- DECIMAL_ROUND: 3,
1213
- DECIMAL_FIT: 4
1214
- };
1215
- let f32Array = new Float32Array(1);
1216
- let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1217
- function roundFloat32(float32Number) {
1218
- f32Array[0] = float32Number;
1219
- let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1220
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1221
- }
1222
- function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1223
- readStruct = updatedReadStruct;
1224
- onLoadedStructures = loadedStructs;
1225
- onSaveState = saveState;
1226
- }
1227
-
1228
- exports.C1 = C1;
1229
- exports.C1Type = C1Type;
1230
- exports.Decoder = Decoder;
1231
- exports.FLOAT32_OPTIONS = FLOAT32_OPTIONS;
1232
- exports.Unpackr = Unpackr;
1233
- exports.addExtension = addExtension;
1234
- exports.checkedRead = checkedRead;
1235
- exports.clearSource = clearSource;
1236
- exports.decode = decode;
1237
- exports.getPosition = getPosition;
1238
- exports.loadStructures = loadStructures;
1239
- exports.mult10 = mult10;
1240
- exports.read = read;
1241
- exports.readString = readString;
1242
- exports.roundFloat32 = roundFloat32;
1243
- exports.setExtractor = setExtractor;
1244
- exports.setReadStruct = setReadStruct;
1245
- exports.typedArrays = typedArrays;
1246
- exports.unpack = unpack;
1247
- exports.unpackMultiple = unpackMultiple;
1248
-
1249
- }));
1250
- //# sourceMappingURL=unpack-no-eval.cjs.map