harperdb 3.2.0 → 3.3.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 (578) hide show
  1. package/README.md +20 -11
  2. package/bin/BinObjects.jsc +0 -0
  3. package/bin/harperdb.jsc +0 -0
  4. package/bin/install.jsc +0 -0
  5. package/bin/register.jsc +0 -0
  6. package/bin/run.jsc +0 -0
  7. package/bin/stop.jsc +0 -0
  8. package/bin/upgrade.jsc +0 -0
  9. package/bin/utility.jsc +0 -0
  10. package/bin/version.jsc +0 -0
  11. package/coverage/lcov.info +6624 -6141
  12. package/data_layer/CreateAttributeObject.jsc +0 -0
  13. package/data_layer/CreateTableObject.jsc +0 -0
  14. package/data_layer/DataLayerObjects.jsc +0 -0
  15. package/data_layer/DeleteBeforeObject.jsc +0 -0
  16. package/data_layer/DeleteObject.jsc +0 -0
  17. package/data_layer/DropAttributeObject.jsc +0 -0
  18. package/data_layer/InsertObject.jsc +0 -0
  19. package/data_layer/ReadTransactionLogObject.jsc +0 -0
  20. package/data_layer/SQLSearch.jsc +0 -0
  21. package/data_layer/SearchByConditionsObject.jsc +0 -0
  22. package/data_layer/SearchByHashObject.jsc +0 -0
  23. package/data_layer/SearchObject.jsc +0 -0
  24. package/data_layer/SqlSearchObject.jsc +0 -0
  25. package/data_layer/UpdateObject.jsc +0 -0
  26. package/data_layer/UpsertObject.jsc +0 -0
  27. package/data_layer/bulkLoad.jsc +0 -0
  28. package/data_layer/data_objects/BulkLoadObjects.jsc +0 -0
  29. package/data_layer/data_objects/UpsertObject.jsc +0 -0
  30. package/data_layer/delete.jsc +0 -0
  31. package/data_layer/export.jsc +0 -0
  32. package/data_layer/harperBridge/BridgeMethods.jsc +0 -0
  33. package/data_layer/harperBridge/bridgeUtility/checkForNewAttr.jsc +0 -0
  34. package/data_layer/harperBridge/bridgeUtility/convertOperationToTransaction.jsc +0 -0
  35. package/data_layer/harperBridge/bridgeUtility/evaluateTableGetAttributes.jsc +0 -0
  36. package/data_layer/harperBridge/bridgeUtility/insertUpdateReturnObj.jsc +0 -0
  37. package/data_layer/harperBridge/bridgeUtility/insertUpdateValidate.jsc +0 -0
  38. package/data_layer/harperBridge/harperBridge.jsc +0 -0
  39. package/data_layer/harperBridge/lmdbBridge/LMDBBridge.jsc +0 -0
  40. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/DeleteTransactionsBeforeResults.jsc +0 -0
  41. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.jsc +0 -0
  42. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.jsc +0 -0
  43. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.jsc +0 -0
  44. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.jsc +0 -0
  45. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.jsc +0 -0
  46. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecordsBefore.jsc +0 -0
  47. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteTransactionLogsBefore.jsc +0 -0
  48. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.jsc +0 -0
  49. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.jsc +0 -0
  50. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.jsc +0 -0
  51. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.jsc +0 -0
  52. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.jsc +0 -0
  53. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadTransactionLog.jsc +0 -0
  54. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.jsc +0 -0
  55. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.jsc +0 -0
  56. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.jsc +0 -0
  57. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.jsc +0 -0
  58. package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.jsc +0 -0
  59. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.jsc +0 -0
  60. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBDeleteTransactionObject.jsc +0 -0
  61. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBInsertTransactionObject.jsc +0 -0
  62. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBTransactionObject.jsc +0 -0
  63. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpdateTransactionObject.jsc +0 -0
  64. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpsertTransactionObject.jsc +0 -0
  65. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.jsc +0 -0
  66. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/ThreadSearchObject.jsc +0 -0
  67. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.jsc +0 -0
  68. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.jsc +0 -0
  69. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.jsc +0 -0
  70. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsEnvironment.jsc +0 -0
  71. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbDropAllAttributes.jsc +0 -0
  72. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.jsc +0 -0
  73. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.jsc +0 -0
  74. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.jsc +0 -0
  75. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbThreadSearch.jsc +0 -0
  76. package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.jsc +0 -0
  77. package/data_layer/hdbInfoController.jsc +0 -0
  78. package/data_layer/insert.jsc +0 -0
  79. package/data_layer/readTransactionLog.jsc +0 -0
  80. package/data_layer/schema.jsc +0 -0
  81. package/data_layer/schemaDescribe.jsc +0 -0
  82. package/data_layer/search.jsc +0 -0
  83. package/data_layer/update.jsc +0 -0
  84. package/events/ClusterStatusEmitter.jsc +0 -0
  85. package/events/SioServerStoppedEvent.jsc +0 -0
  86. package/events/SocketClusterStatusEmitter.jsc +0 -0
  87. package/license/LICENSE +91 -1
  88. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/README.md +1 -0
  89. package/node_modules/{node-addon-api/src/nothing.c → @msgpackr-extract/msgpackr-extract-linux-x64/index.js} +0 -0
  90. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.glibc.node +0 -0
  91. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.musl.node +0 -0
  92. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.glibc.node +0 -0
  93. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.musl.node +0 -0
  94. package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/package.json +53 -0
  95. package/node_modules/{msgpackr-extract → lmdb-store}/.github/workflows/prebuild.yml +9 -10
  96. package/node_modules/lmdb-store/.idea/lmdb-store.iml +12 -0
  97. package/node_modules/lmdb-store/.idea/misc.xml +6 -0
  98. package/node_modules/lmdb-store/.idea/modules.xml +8 -0
  99. package/node_modules/lmdb-store/.idea/workspace.xml +4 -0
  100. package/node_modules/lmdb-store/README.md +393 -388
  101. package/node_modules/lmdb-store/benchmark/index.js +162 -162
  102. package/node_modules/lmdb-store/binding.gyp +79 -88
  103. package/node_modules/lmdb-store/caching.js +113 -113
  104. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
  105. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
  106. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
  107. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
  108. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
  109. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
  110. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
  111. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.c +12125 -12125
  112. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
  113. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
  114. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
  115. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
  116. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
  117. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
  118. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
  119. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
  120. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
  121. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
  122. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
  123. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
  124. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
  125. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
  126. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
  127. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
  128. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
  129. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
  130. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
  131. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
  132. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
  133. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
  134. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
  135. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
  136. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
  137. package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
  138. package/node_modules/lmdb-store/dependencies/lz4/LICENSE +11 -11
  139. package/node_modules/lmdb-store/dependencies/lz4/lib/README.md +137 -137
  140. package/node_modules/lmdb-store/dependencies/lz4/lib/dll/example/README.md +69 -69
  141. package/node_modules/lmdb-store/dependencies/lz4/lib/lz4frame.c +1899 -1899
  142. package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.c +1030 -1030
  143. package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.h +328 -328
  144. package/node_modules/lmdb-store/dist/index.cjs +2591 -0
  145. package/node_modules/lmdb-store/dist/index.cjs.map +1 -0
  146. package/node_modules/lmdb-store/index.d.ts +323 -323
  147. package/node_modules/lmdb-store/index.js +1274 -1274
  148. package/node_modules/lmdb-store/index.mjs +3 -3
  149. package/node_modules/lmdb-store/package.json +16 -11
  150. package/node_modules/lmdb-store/prebuilds/darwin-arm64/electron.abi98.node +0 -0
  151. package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi83.node +0 -0
  152. package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi93.node +0 -0
  153. package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi98.node +0 -0
  154. package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi83.node +0 -0
  155. package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi93.node +0 -0
  156. package/node_modules/lmdb-store/prebuilds/linux-arm64/electron.abi98.node +0 -0
  157. package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi83.node +0 -0
  158. package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi93.node +0 -0
  159. package/node_modules/lmdb-store/prebuilds/linux-x64/electron.abi98.node +0 -0
  160. package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.musl.node +0 -0
  161. package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.node +0 -0
  162. package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.musl.node +0 -0
  163. package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.node +0 -0
  164. package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi98.node +0 -0
  165. package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi83.node +0 -0
  166. package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi93.node +0 -0
  167. package/node_modules/lmdb-store/src/compression.cpp +181 -181
  168. package/node_modules/lmdb-store/src/cursor.cpp +407 -407
  169. package/node_modules/lmdb-store/src/dbi.cpp +354 -354
  170. package/node_modules/lmdb-store/src/env.cpp +1134 -1134
  171. package/node_modules/lmdb-store/src/misc.cpp +528 -528
  172. package/node_modules/lmdb-store/src/node-lmdb.cpp +44 -44
  173. package/node_modules/lmdb-store/src/node-lmdb.h +965 -965
  174. package/node_modules/lmdb-store/src/ordered-binary.cpp +337 -337
  175. package/node_modules/lmdb-store/src/txn.cpp +513 -513
  176. package/node_modules/lmdb-store/src/v8-fast-api-calls.h +419 -419
  177. package/node_modules/lmdb-store/src/windows.c +30 -30
  178. package/node_modules/lmdb-store/test/index.test.js +584 -584
  179. package/node_modules/lmdb-store/test/node-lmdb.test.js +1525 -1525
  180. package/node_modules/lmdb-store/test/threads.js +100 -100
  181. package/node_modules/lmdb-store/util/ArrayLikeIterable.js +136 -136
  182. package/node_modules/lmdb-store/util/WeakValueMap.js +40 -40
  183. package/node_modules/lmdb-store/util/upgrade-lmdb.js +46 -46
  184. package/node_modules/lmdb-store/util/when.js +8 -8
  185. package/node_modules/microtime/.github/workflows/release.yml +76 -0
  186. package/node_modules/microtime/.github/workflows/test.yml +46 -0
  187. package/node_modules/microtime/README.md +0 -2
  188. package/node_modules/microtime/binding.gyp +28 -10
  189. package/node_modules/microtime/package.json +25 -20
  190. package/node_modules/microtime/prebuilds/darwin-x64+arm64/electron.napi.node +0 -0
  191. package/node_modules/microtime/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  192. package/node_modules/microtime/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  193. package/node_modules/microtime/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  194. package/node_modules/microtime/prebuilds/linux-x64/electron.napi.node +0 -0
  195. package/node_modules/microtime/prebuilds/linux-x64/node.napi.node +0 -0
  196. package/node_modules/microtime/prebuilds/win32-ia32/electron.napi.node +0 -0
  197. package/node_modules/microtime/prebuilds/win32-ia32/node.napi.node +0 -0
  198. package/node_modules/microtime/prebuilds/win32-x64/electron.napi.node +0 -0
  199. package/node_modules/microtime/prebuilds/win32-x64/node.napi.node +0 -0
  200. package/node_modules/msgpackr/dist/index.js +1929 -1917
  201. package/node_modules/msgpackr/dist/index.min.js +67 -68
  202. package/node_modules/msgpackr/dist/node.cjs +1994 -1980
  203. package/node_modules/msgpackr/dist/test.js +683 -1235
  204. package/node_modules/msgpackr/index.d.ts +23 -12
  205. package/node_modules/msgpackr/node-index.js +23 -21
  206. package/node_modules/msgpackr/pack.js +935 -931
  207. package/node_modules/msgpackr/package.json +24 -12
  208. package/node_modules/msgpackr/unpack.d.ts +52 -50
  209. package/node_modules/msgpackr/unpack.js +1061 -1053
  210. package/node_modules/msgpackr-extract/bin/download-prebuilds.js +11 -0
  211. package/node_modules/msgpackr-extract/binding.gyp +22 -5
  212. package/node_modules/msgpackr-extract/index.js +1 -1
  213. package/node_modules/msgpackr-extract/package.json +46 -21
  214. package/node_modules/msgpackr-extract/src/.vs/ProjectSettings.json +3 -0
  215. package/node_modules/msgpackr-extract/src/.vs/VSWorkspaceState.json +7 -0
  216. package/node_modules/msgpackr-extract/src/.vs/slnx.sqlite +0 -0
  217. package/node_modules/msgpackr-extract/src/.vs/src/v16/.suo +0 -0
  218. package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db +0 -0
  219. package/node_modules/msgpackr-extract/{prebuilds/darwin-x64/node.abi72.node → src/.vs/src/v16/Browse.VC.db-shm} +0 -0
  220. package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db-wal +0 -0
  221. package/node_modules/msgpackr-extract/src/extract.cpp +272 -269
  222. package/node_modules/nan/package.json +0 -1
  223. package/node_modules/node-addon-api/README.md +146 -53
  224. package/node_modules/node-addon-api/common.gypi +21 -0
  225. package/node_modules/node-addon-api/except.gypi +25 -0
  226. package/node_modules/node-addon-api/index.js +7 -41
  227. package/node_modules/node-addon-api/napi-inl.deprecated.h +8 -8
  228. package/node_modules/node-addon-api/napi-inl.h +2795 -633
  229. package/node_modules/node-addon-api/napi.h +1547 -597
  230. package/node_modules/node-addon-api/node_api.gyp +9 -0
  231. package/node_modules/node-addon-api/noexcept.gypi +26 -0
  232. package/node_modules/node-addon-api/nothing.c +0 -0
  233. package/node_modules/node-addon-api/package-support.json +21 -0
  234. package/node_modules/node-addon-api/package.json +203 -13
  235. package/node_modules/node-addon-api/tools/README.md +12 -6
  236. package/node_modules/node-addon-api/tools/clang-format.js +71 -0
  237. package/node_modules/node-addon-api/tools/conversion.js +4 -8
  238. package/node_modules/node-addon-api/tools/eslint-format.js +71 -0
  239. package/node_modules/node-gyp-build/README.md +17 -14
  240. package/node_modules/node-gyp-build/bin.js +28 -15
  241. package/node_modules/node-gyp-build/index.js +145 -34
  242. package/node_modules/node-gyp-build/package.json +18 -15
  243. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/LICENSE +0 -0
  244. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/README.md +0 -0
  245. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/bin.js +1 -1
  246. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/build-test.js +0 -0
  247. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/index.js +17 -11
  248. package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/optional.js +0 -0
  249. package/node_modules/{msgpackr-extract/node_modules/node-gyp-build → node-gyp-build-optional-packages}/package.json +17 -17
  250. package/package.json +12 -11
  251. package/security/JWTObjects.jsc +0 -0
  252. package/security/auth.jsc +0 -0
  253. package/security/cryptoHash.jsc +0 -0
  254. package/security/data_objects/PermissionAttributeResponseObject.jsc +0 -0
  255. package/security/data_objects/PermissionResponseObject.jsc +0 -0
  256. package/security/data_objects/PermissionTableResponseObject.jsc +0 -0
  257. package/security/permissionsTranslator.jsc +0 -0
  258. package/security/role.jsc +0 -0
  259. package/security/tokenAuthentication.jsc +0 -0
  260. package/security/user.jsc +0 -0
  261. package/server/ClusteringOriginObject.jsc +0 -0
  262. package/server/JobObject.jsc +0 -0
  263. package/server/clustering/ClusterStatusObject.jsc +0 -0
  264. package/server/clustering/NodeObject.jsc +0 -0
  265. package/server/clustering/clusterUtilities.jsc +0 -0
  266. package/server/configuration.jsc +0 -0
  267. package/server/customFunctions/customFunctionsServer.jsc +0 -0
  268. package/server/customFunctions/helpers/getCORSOptions.jsc +0 -0
  269. package/server/customFunctions/helpers/getHeaderTimeoutConfig.jsc +0 -0
  270. package/server/customFunctions/helpers/getServerOptions.jsc +0 -0
  271. package/server/customFunctions/operations.jsc +0 -0
  272. package/server/customFunctions/operationsValidation.jsc +0 -0
  273. package/server/harperdb/hdbServer.jsc +0 -0
  274. package/server/ipc/IPCClient.jsc +0 -0
  275. package/server/ipc/hdbIpcServer.jsc +0 -0
  276. package/server/ipc/serverHandlers.jsc +0 -0
  277. package/server/ipc/utility/IPCEventObject.jsc +0 -0
  278. package/server/ipc/utility/ipcUtils.jsc +0 -0
  279. package/server/jobRunner.jsc +0 -0
  280. package/server/jobThread.jsc +0 -0
  281. package/server/jobs.jsc +0 -0
  282. package/server/serverHelpers/OperationFunctionObject.jsc +0 -0
  283. package/server/serverHelpers/requestTimePlugin.jsc +0 -0
  284. package/server/serverHelpers/serverHandlers.jsc +0 -0
  285. package/server/serverHelpers/serverUtilities.jsc +0 -0
  286. package/server/socketcluster/Server.jsc +0 -0
  287. package/server/socketcluster/broker.jsc +0 -0
  288. package/server/socketcluster/connector/HDBSocketConnector.jsc +0 -0
  289. package/server/socketcluster/connector/InterNodeSocketConnector.jsc +0 -0
  290. package/server/socketcluster/connector/SocketConnector.jsc +0 -0
  291. package/server/socketcluster/connector/spawnSCConnection.jsc +0 -0
  292. package/server/socketcluster/decisionMatrix/CoreDecisionMatrix.jsc +0 -0
  293. package/server/socketcluster/decisionMatrix/DecisionMatrixIF.jsc +0 -0
  294. package/server/socketcluster/decisionMatrix/rules/AssignToHdbChildWorkerRule.jsc +0 -0
  295. package/server/socketcluster/decisionMatrix/rules/CallRoomMsgHandlerRule.jsc +0 -0
  296. package/server/socketcluster/decisionMatrix/rules/CleanDataObjectRule.jsc +0 -0
  297. package/server/socketcluster/decisionMatrix/rules/CommandCollection.jsc +0 -0
  298. package/server/socketcluster/decisionMatrix/rules/DummyRule.jsc +0 -0
  299. package/server/socketcluster/decisionMatrix/rules/RulesIF.jsc +0 -0
  300. package/server/socketcluster/decisionMatrix/rules/StripHdbHeaderRule.jsc +0 -0
  301. package/server/socketcluster/decisionMatrix/rules/TestRule.jsc +0 -0
  302. package/server/socketcluster/handlers/NodeConnectionsHandler.jsc +0 -0
  303. package/server/socketcluster/handlers/SCServer.jsc +0 -0
  304. package/server/socketcluster/handlers/ServerSocket.jsc +0 -0
  305. package/server/socketcluster/interNodeConnectionLauncher.jsc +0 -0
  306. package/server/socketcluster/messageQueue/MessageQueueIF.jsc +0 -0
  307. package/server/socketcluster/middleware/AuthMiddleware.jsc +0 -0
  308. package/server/socketcluster/middleware/ConnectionNameCheckMiddleware.jsc +0 -0
  309. package/server/socketcluster/middleware/GenericMiddleware.jsc +0 -0
  310. package/server/socketcluster/middleware/MessagePrepMiddleware.jsc +0 -0
  311. package/server/socketcluster/middleware/MiddlewareFactory.jsc +0 -0
  312. package/server/socketcluster/middleware/MiddlewareIF.jsc +0 -0
  313. package/server/socketcluster/middleware/OriginatorCheckMiddleware.jsc +0 -0
  314. package/server/socketcluster/middleware/RequestDataValidMiddleware.jsc +0 -0
  315. package/server/socketcluster/middleware/StampOriginatorMiddleware.jsc +0 -0
  316. package/server/socketcluster/middleware/StampRequestMiddleware.jsc +0 -0
  317. package/server/socketcluster/observer/EventableIF.jsc +0 -0
  318. package/server/socketcluster/room/AddUserRoom.jsc +0 -0
  319. package/server/socketcluster/room/AlterUserRoom.jsc +0 -0
  320. package/server/socketcluster/room/CoreRoom.jsc +0 -0
  321. package/server/socketcluster/room/CreateAttributeRoom.jsc +0 -0
  322. package/server/socketcluster/room/CreateSchemaRoom.jsc +0 -0
  323. package/server/socketcluster/room/CreateTableRoom.jsc +0 -0
  324. package/server/socketcluster/room/DropUserRoom.jsc +0 -0
  325. package/server/socketcluster/room/HDBNodeRoom.jsc +0 -0
  326. package/server/socketcluster/room/RoomIF.jsc +0 -0
  327. package/server/socketcluster/room/RoomMessageObjects.jsc +0 -0
  328. package/server/socketcluster/room/UsersRoom.jsc +0 -0
  329. package/server/socketcluster/room/WatchHDBWorkersRoom.jsc +0 -0
  330. package/server/socketcluster/room/WorkerRoom.jsc +0 -0
  331. package/server/socketcluster/room/roomFactory.jsc +0 -0
  332. package/server/socketcluster/socketClusterObjects.jsc +0 -0
  333. package/server/socketcluster/types.jsc +0 -0
  334. package/server/socketcluster/util/clusterData.jsc +0 -0
  335. package/server/socketcluster/util/socketClusterUtils.jsc +0 -0
  336. package/server/socketcluster/worker/ClusterWorker.jsc +0 -0
  337. package/server/socketcluster/worker/WorkerIF.jsc +0 -0
  338. package/server/socketcluster/worker/WorkerObjects.jsc +0 -0
  339. package/server/transactToClusteringUtilities.jsc +0 -0
  340. package/sqlTranslator/SelectValidator.jsc +0 -0
  341. package/sqlTranslator/alasqlFunctionImporter.jsc +0 -0
  342. package/sqlTranslator/conditionPatterns.jsc +0 -0
  343. package/sqlTranslator/deleteTranslator.jsc +0 -0
  344. package/sqlTranslator/index.jsc +0 -0
  345. package/sqlTranslator/sql_statement_bucket.jsc +0 -0
  346. package/upgrade/EnvironmentVariable.jsc +0 -0
  347. package/upgrade/UpgradeDirective.jsc +0 -0
  348. package/upgrade/UpgradeObjects.jsc +0 -0
  349. package/upgrade/directives/3-0-0.jsc +0 -0
  350. package/upgrade/directives/3-1-0.jsc +0 -0
  351. package/upgrade/directives/directivesController.jsc +0 -0
  352. package/upgrade/directives/upgrade_scripts/3_0_0_reindex_script.jsc +0 -0
  353. package/upgrade/directivesManager.jsc +0 -0
  354. package/upgrade/lmdb/nodeLMDB/DBIDefinition.jsc +0 -0
  355. package/upgrade/lmdb/nodeLMDB/OpenDBIObject.jsc +0 -0
  356. package/upgrade/lmdb/nodeLMDB/OpenEnvironmentObject.jsc +0 -0
  357. package/upgrade/lmdb/nodeLMDB/commonErrors.jsc +0 -0
  358. package/upgrade/lmdb/nodeLMDB/commonUtility.jsc +0 -0
  359. package/upgrade/lmdb/nodeLMDB/environmentUtility.jsc +0 -0
  360. package/upgrade/lmdb/nodeLMDB/terms.jsc +0 -0
  361. package/upgrade/upgradePrompt.jsc +0 -0
  362. package/upgrade/upgradeUtilities.jsc +0 -0
  363. package/utility/AWS/AWSConnector.jsc +0 -0
  364. package/utility/OperationFunctionCaller.jsc +0 -0
  365. package/utility/common_utils.jsc +0 -0
  366. package/utility/environment/SystemInformationObject.jsc +0 -0
  367. package/utility/environment/SystemInformationOperation.jsc +0 -0
  368. package/utility/environment/environmentManager.jsc +0 -0
  369. package/utility/environment/systemInformation.jsc +0 -0
  370. package/utility/errors/commonErrors.jsc +0 -0
  371. package/utility/errors/hdbError.jsc +0 -0
  372. package/utility/functions/date/dateFunctions.jsc +0 -0
  373. package/utility/functions/geo.jsc +0 -0
  374. package/utility/functions/math/avg.jsc +0 -0
  375. package/utility/functions/math/count.jsc +0 -0
  376. package/utility/functions/sql/alaSQLExtension.jsc +0 -0
  377. package/utility/functions/string/compare.jsc +0 -0
  378. package/utility/globalSchema.jsc +0 -0
  379. package/utility/hdbTerms.jsc +0 -0
  380. package/utility/install/checkJWTTokensExist.jsc +0 -0
  381. package/utility/install/installer.jsc +0 -0
  382. package/utility/install_user_permission.jsc +0 -0
  383. package/utility/lmdb/DBIDefinition.jsc +0 -0
  384. package/utility/lmdb/DeleteRecordsResponseObject.jsc +0 -0
  385. package/utility/lmdb/InsertRecordsResponseObject.jsc +0 -0
  386. package/utility/lmdb/OpenDBIObject.jsc +0 -0
  387. package/utility/lmdb/OpenEnvironmentObject.jsc +0 -0
  388. package/utility/lmdb/UpdateRecordsResponseObject.jsc +0 -0
  389. package/utility/lmdb/UpsertRecordsResponseObject.jsc +0 -0
  390. package/utility/lmdb/cleanLMDBMap.jsc +0 -0
  391. package/utility/lmdb/commonUtility.jsc +0 -0
  392. package/utility/lmdb/deleteUtility.jsc +0 -0
  393. package/utility/lmdb/environmentUtility.jsc +0 -0
  394. package/utility/lmdb/searchCursorFunctions.jsc +0 -0
  395. package/utility/lmdb/searchUtility.jsc +0 -0
  396. package/utility/lmdb/terms.jsc +0 -0
  397. package/utility/lmdb/writeUtility.jsc +0 -0
  398. package/utility/logging/harper_logger.jsc +0 -0
  399. package/utility/mount_hdb.jsc +0 -0
  400. package/utility/npmUtilities.jsc +0 -0
  401. package/utility/operation_authorization.jsc +0 -0
  402. package/utility/password.jsc +0 -0
  403. package/utility/pm2/servicesConfig.jsc +0 -0
  404. package/utility/pm2/utilityFunctions.jsc +0 -0
  405. package/utility/psList.jsc +0 -0
  406. package/utility/registration/hdb_license.jsc +0 -0
  407. package/utility/registration/licenseObjects.jsc +0 -0
  408. package/utility/registration/registrationHandler.jsc +0 -0
  409. package/utility/scripts/restartHdb.jsc +0 -0
  410. package/utility/signalling.jsc +0 -0
  411. package/utility/system_info.jsc +0 -0
  412. package/validation/bulkDeleteValidator.jsc +0 -0
  413. package/validation/check_permissions.jsc +0 -0
  414. package/validation/clustering/configureValidator.jsc +0 -0
  415. package/validation/common_validators.jsc +0 -0
  416. package/validation/conditionalDeleteValidator.jsc +0 -0
  417. package/validation/deleteValidator.jsc +0 -0
  418. package/validation/fileLoadValidator.jsc +0 -0
  419. package/validation/insertValidator.jsc +0 -0
  420. package/validation/nodeSubscriptionValidator.jsc +0 -0
  421. package/validation/nodeValidator.jsc +0 -0
  422. package/validation/readLogValidator.jsc +0 -0
  423. package/validation/registration/license_key_object.jsc +0 -0
  424. package/validation/role_validation.jsc +0 -0
  425. package/validation/schemaMetadataValidator.jsc +0 -0
  426. package/validation/schema_validator.jsc +0 -0
  427. package/validation/searchValidator.jsc +0 -0
  428. package/validation/user_validation.jsc +0 -0
  429. package/validation/validationWrapper.jsc +0 -0
  430. package/node_modules/lmdb-store/build/Makefile +0 -324
  431. package/node_modules/lmdb-store/build/Release/.deps/Release/lmdb-store.node.d +0 -1
  432. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o.d +0 -6
  433. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o.d +0 -8
  434. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o.d +0 -8
  435. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o.d +0 -5
  436. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/compression.o.d +0 -72
  437. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/cursor.o.d +0 -73
  438. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/dbi.o.d +0 -73
  439. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/env.o.d +0 -73
  440. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/misc.o.d +0 -73
  441. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/node-lmdb.o.d +0 -73
  442. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/ordered-binary.o.d +0 -73
  443. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/txn.o.d +0 -73
  444. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/windows.o.d +0 -3
  445. package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store.node.d +0 -1
  446. package/node_modules/lmdb-store/build/Release/lmdb-store.node +0 -0
  447. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o +0 -0
  448. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o +0 -0
  449. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o +0 -0
  450. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o +0 -0
  451. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/compression.o +0 -0
  452. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/cursor.o +0 -0
  453. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/dbi.o +0 -0
  454. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/env.o +0 -0
  455. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/misc.o +0 -0
  456. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/node-lmdb.o +0 -0
  457. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/ordered-binary.o +0 -0
  458. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/txn.o +0 -0
  459. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/windows.o +0 -0
  460. package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store.node +0 -0
  461. package/node_modules/lmdb-store/build/binding.Makefile +0 -6
  462. package/node_modules/lmdb-store/build/config.gypi +0 -426
  463. package/node_modules/lmdb-store/build/lmdb-store.target.mk +0 -206
  464. package/node_modules/lmdb-store/node_modules/node-gyp-build/package.json +0 -60
  465. package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi87.node +0 -0
  466. package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi72.node +0 -0
  467. package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi88.node +0 -0
  468. package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi87.node +0 -0
  469. package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi72.node +0 -0
  470. package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi88.node +0 -0
  471. package/node_modules/microtime/prebuilds/darwin-x64/electron-napi.node +0 -0
  472. package/node_modules/microtime/prebuilds/darwin-x64/node-napi.node +0 -0
  473. package/node_modules/microtime/prebuilds/linux-arm/electron-napi.node +0 -0
  474. package/node_modules/microtime/prebuilds/linux-arm/node-napi.node +0 -0
  475. package/node_modules/microtime/prebuilds/linux-x64/electron-napi.node +0 -0
  476. package/node_modules/microtime/prebuilds/linux-x64/node-napi.node +0 -0
  477. package/node_modules/microtime/prebuilds/win32-x64/electron-napi.node +0 -0
  478. package/node_modules/microtime/prebuilds/win32-x64/node-napi.node +0 -0
  479. package/node_modules/msgpackr-extract/.circleci/config.yml +0 -19
  480. package/node_modules/msgpackr-extract/.travis.yml +0 -30
  481. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/LICENSE +0 -21
  482. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/README.md +0 -58
  483. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/bin.js +0 -77
  484. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/build-test.js +0 -19
  485. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/index.js +0 -202
  486. package/node_modules/msgpackr-extract/node_modules/node-gyp-build/optional.js +0 -7
  487. package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/electron.abi98.node +0 -0
  488. package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi102.node +0 -0
  489. package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi83.node +0 -0
  490. package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi93.node +0 -0
  491. package/node_modules/msgpackr-extract/prebuilds/darwin-x64/electron.abi98.node +0 -0
  492. package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi102.node +0 -0
  493. package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi83.node +0 -0
  494. package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi88.node +0 -0
  495. package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi93.node +0 -0
  496. package/node_modules/msgpackr-extract/prebuilds/linux-arm64/electron.abi98.node +0 -0
  497. package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi102.node +0 -0
  498. package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi83.node +0 -0
  499. package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi93.node +0 -0
  500. package/node_modules/msgpackr-extract/prebuilds/linux-x64/electron.abi98.node +0 -0
  501. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.musl.node +0 -0
  502. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.node +0 -0
  503. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.musl.node +0 -0
  504. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.node +0 -0
  505. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.musl.node +0 -0
  506. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.node +0 -0
  507. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi88.node +0 -0
  508. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.musl.node +0 -0
  509. package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.node +0 -0
  510. package/node_modules/msgpackr-extract/prebuilds/win32-x64/electron.abi98.node +0 -0
  511. package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi102.node +0 -0
  512. package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi72.node +0 -0
  513. package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi83.node +0 -0
  514. package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi88.node +0 -0
  515. package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi93.node +0 -0
  516. package/node_modules/node-addon-api/.editorconfig +0 -8
  517. package/node_modules/node-addon-api/.travis.yml +0 -65
  518. package/node_modules/node-addon-api/CHANGELOG.md +0 -325
  519. package/node_modules/node-addon-api/CODE_OF_CONDUCT.md +0 -4
  520. package/node_modules/node-addon-api/CONTRIBUTING.md +0 -66
  521. package/node_modules/node-addon-api/appveyor.yml +0 -48
  522. package/node_modules/node-addon-api/doc/Doxyfile +0 -2450
  523. package/node_modules/node-addon-api/doc/array_buffer.md +0 -129
  524. package/node_modules/node-addon-api/doc/async_context.md +0 -76
  525. package/node_modules/node-addon-api/doc/async_operations.md +0 -31
  526. package/node_modules/node-addon-api/doc/async_worker.md +0 -397
  527. package/node_modules/node-addon-api/doc/basic_types.md +0 -415
  528. package/node_modules/node-addon-api/doc/bigint.md +0 -92
  529. package/node_modules/node-addon-api/doc/boolean.md +0 -64
  530. package/node_modules/node-addon-api/doc/buffer.md +0 -140
  531. package/node_modules/node-addon-api/doc/callback_scope.md +0 -54
  532. package/node_modules/node-addon-api/doc/callbackinfo.md +0 -97
  533. package/node_modules/node-addon-api/doc/checker-tool.md +0 -32
  534. package/node_modules/node-addon-api/doc/class_property_descriptor.md +0 -118
  535. package/node_modules/node-addon-api/doc/cmake-js.md +0 -19
  536. package/node_modules/node-addon-api/doc/conversion-tool.md +0 -28
  537. package/node_modules/node-addon-api/doc/creating_a_release.md +0 -62
  538. package/node_modules/node-addon-api/doc/dataview.md +0 -244
  539. package/node_modules/node-addon-api/doc/env.md +0 -63
  540. package/node_modules/node-addon-api/doc/error.md +0 -115
  541. package/node_modules/node-addon-api/doc/error_handling.md +0 -186
  542. package/node_modules/node-addon-api/doc/escapable_handle_scope.md +0 -82
  543. package/node_modules/node-addon-api/doc/external.md +0 -59
  544. package/node_modules/node-addon-api/doc/function.md +0 -294
  545. package/node_modules/node-addon-api/doc/function_reference.md +0 -238
  546. package/node_modules/node-addon-api/doc/generator.md +0 -13
  547. package/node_modules/node-addon-api/doc/handle_scope.md +0 -65
  548. package/node_modules/node-addon-api/doc/memory_management.md +0 -27
  549. package/node_modules/node-addon-api/doc/node-gyp.md +0 -82
  550. package/node_modules/node-addon-api/doc/number.md +0 -163
  551. package/node_modules/node-addon-api/doc/object.md +0 -202
  552. package/node_modules/node-addon-api/doc/object_lifetime_management.md +0 -83
  553. package/node_modules/node-addon-api/doc/object_reference.md +0 -117
  554. package/node_modules/node-addon-api/doc/object_wrap.md +0 -546
  555. package/node_modules/node-addon-api/doc/prebuild_tools.md +0 -16
  556. package/node_modules/node-addon-api/doc/promises.md +0 -74
  557. package/node_modules/node-addon-api/doc/property_descriptor.md +0 -231
  558. package/node_modules/node-addon-api/doc/range_error.md +0 -59
  559. package/node_modules/node-addon-api/doc/reference.md +0 -111
  560. package/node_modules/node-addon-api/doc/setup.md +0 -82
  561. package/node_modules/node-addon-api/doc/string.md +0 -89
  562. package/node_modules/node-addon-api/doc/symbol.md +0 -44
  563. package/node_modules/node-addon-api/doc/threadsafe_function.md +0 -303
  564. package/node_modules/node-addon-api/doc/type_error.md +0 -59
  565. package/node_modules/node-addon-api/doc/typed_array.md +0 -74
  566. package/node_modules/node-addon-api/doc/typed_array_of.md +0 -133
  567. package/node_modules/node-addon-api/doc/value.md +0 -269
  568. package/node_modules/node-addon-api/doc/version_management.md +0 -43
  569. package/node_modules/node-addon-api/doc/working_with_javascript_values.md +0 -14
  570. package/node_modules/node-addon-api/external-napi/node_api.h +0 -7
  571. package/node_modules/node-addon-api/src/node_api.cc +0 -3655
  572. package/node_modules/node-addon-api/src/node_api.gyp +0 -21
  573. package/node_modules/node-addon-api/src/node_api.h +0 -588
  574. package/node_modules/node-addon-api/src/node_api_types.h +0 -115
  575. package/node_modules/node-addon-api/src/node_internals.cc +0 -142
  576. package/node_modules/node-addon-api/src/node_internals.h +0 -157
  577. package/node_modules/node-addon-api/src/util-inl.h +0 -38
  578. package/node_modules/node-addon-api/src/util.h +0 -7
@@ -5,1973 +5,1985 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var stream = require('stream');
6
6
  var module$1 = require('module');
7
7
 
8
- var decoder;
9
- try {
10
- decoder = new TextDecoder();
11
- } catch(error) {}
12
- var src;
13
- var srcEnd;
14
- var position = 0;
15
- const EMPTY_ARRAY = [];
16
- var strings = EMPTY_ARRAY;
17
- var stringPosition = 0;
18
- var currentUnpackr = {};
19
- var currentStructures;
20
- var srcString;
21
- var srcStringStart = 0;
22
- var srcStringEnd = 0;
23
- var bundledStrings;
24
- var referenceMap;
25
- var currentExtensions = [];
26
- var dataView;
27
- var defaultOptions = {
28
- useRecords: false,
29
- mapsAsObjects: true
30
- };
31
- class C1Type {}
32
- const C1 = new C1Type();
33
- C1.name = 'MessagePack 0xC1';
34
- var sequentialMode = false;
35
- var inlineObjectReadThreshold = 2;
36
- try {
37
- new Function('');
38
- } catch(error) {
39
- // if eval variants are not supported, do not create inline object readers ever
40
- inlineObjectReadThreshold = Infinity;
41
- }
42
-
43
- class Unpackr {
44
- constructor(options) {
45
- if (options) {
46
- if (options.useRecords === false && options.mapsAsObjects === undefined)
47
- options.mapsAsObjects = true;
48
- if (options.structures)
49
- options.structures.sharedLength = options.structures.length;
50
- else if (options.getStructures) {
51
- (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
52
- options.structures.sharedLength = 0;
53
- }
54
- }
55
- Object.assign(this, options);
56
- }
57
- unpack(source, end) {
58
- if (src) {
59
- // re-entrant execution, save the state and restore it after we do this unpack
60
- return saveState(() => {
61
- clearSource();
62
- return this ? this.unpack(source, end) : Unpackr.prototype.unpack.call(defaultOptions, source, end)
63
- })
64
- }
65
- srcEnd = end > -1 ? end : source.length;
66
- position = 0;
67
- stringPosition = 0;
68
- srcStringEnd = 0;
69
- srcString = null;
70
- strings = EMPTY_ARRAY;
71
- bundledStrings = null;
72
- src = source;
73
- // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
74
- // technique for getting data from a database where it can be copied into an existing buffer instead of creating
75
- // new ones
76
- try {
77
- dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
78
- } catch(error) {
79
- // if it doesn't have a buffer, maybe it is the wrong type of object
80
- src = null;
81
- if (source instanceof Uint8Array)
82
- throw error
83
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
84
- }
85
- if (this instanceof Unpackr) {
86
- currentUnpackr = this;
87
- if (this.structures) {
88
- currentStructures = this.structures;
89
- return checkedRead()
90
- } else if (!currentStructures || currentStructures.length > 0) {
91
- currentStructures = [];
92
- }
93
- } else {
94
- currentUnpackr = defaultOptions;
95
- if (!currentStructures || currentStructures.length > 0)
96
- currentStructures = [];
97
- }
98
- return checkedRead()
99
- }
100
- unpackMultiple(source, forEach) {
101
- let values, lastPosition = 0;
102
- try {
103
- sequentialMode = true;
104
- let size = source.length;
105
- let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
106
- if (forEach) {
107
- forEach(value);
108
- while(position < size) {
109
- lastPosition = position;
110
- if (forEach(checkedRead()) === false) {
111
- return
112
- }
113
- }
114
- }
115
- else {
116
- values = [ value ];
117
- while(position < size) {
118
- lastPosition = position;
119
- values.push(checkedRead());
120
- }
121
- return values
122
- }
123
- } catch(error) {
124
- error.lastPosition = lastPosition;
125
- error.values = values;
126
- throw error
127
- } finally {
128
- sequentialMode = false;
129
- clearSource();
130
- }
131
- }
132
- _mergeStructures(loadedStructures, existingStructures) {
133
- loadedStructures = loadedStructures || [];
134
- for (let i = 0, l = loadedStructures.length; i < l; i++) {
135
- let structure = loadedStructures[i];
136
- if (structure) {
137
- structure.isShared = true;
138
- if (i >= 32)
139
- structure.highByte = (i - 32) >> 5;
140
- }
141
- }
142
- loadedStructures.sharedLength = loadedStructures.length;
143
- for (let id in existingStructures || []) {
144
- if (id >= 0) {
145
- let structure = loadedStructures[id];
146
- let existing = existingStructures[id];
147
- if (existing) {
148
- if (structure)
149
- (loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure;
150
- loadedStructures[id] = existing;
151
- }
152
- }
153
- }
154
- return this.structures = loadedStructures
155
- }
156
- decode(source, end) {
157
- return this.unpack(source, end)
158
- }
159
- }
160
- function checkedRead() {
161
- try {
162
- if (!currentUnpackr.trusted && !sequentialMode) {
163
- let sharedLength = currentStructures.sharedLength || 0;
164
- if (sharedLength < currentStructures.length)
165
- currentStructures.length = sharedLength;
166
- }
167
- let result = read();
168
- if (bundledStrings) // bundled strings to skip past
169
- position = bundledStrings.postBundlePosition;
170
-
171
- if (position == srcEnd) {
172
- // finished reading this source, cleanup references
173
- if (currentStructures.restoreStructures)
174
- restoreStructures();
175
- currentStructures = null;
176
- src = null;
177
- if (referenceMap)
178
- referenceMap = null;
179
- } else if (position > srcEnd) {
180
- // over read
181
- let error = new Error('Unexpected end of MessagePack data');
182
- error.incomplete = true;
183
- throw error
184
- } else if (!sequentialMode) {
185
- throw new Error('Data read, but end of buffer not reached')
186
- }
187
- // else more to read, but we are reading sequentially, so don't clear source yet
188
- return result
189
- } catch(error) {
190
- if (currentStructures.restoreStructures)
191
- restoreStructures();
192
- clearSource();
193
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
194
- error.incomplete = true;
195
- }
196
- throw error
197
- }
198
- }
199
-
200
- function restoreStructures() {
201
- for (let id in currentStructures.restoreStructures) {
202
- currentStructures[id] = currentStructures.restoreStructures[id];
203
- }
204
- currentStructures.restoreStructures = null;
205
- }
206
-
207
- function read() {
208
- let token = src[position++];
209
- if (token < 0xa0) {
210
- if (token < 0x80) {
211
- if (token < 0x40)
212
- return token
213
- else {
214
- let structure = currentStructures[token & 0x3f] ||
215
- currentUnpackr.getStructures && loadStructures()[token & 0x3f];
216
- if (structure) {
217
- if (!structure.read) {
218
- structure.read = createStructureReader(structure, token & 0x3f);
219
- }
220
- return structure.read()
221
- } else
222
- return token
223
- }
224
- } else if (token < 0x90) {
225
- // map
226
- token -= 0x80;
227
- if (currentUnpackr.mapsAsObjects) {
228
- let object = {};
229
- for (let i = 0; i < token; i++) {
230
- object[readKey()] = read();
231
- }
232
- return object
233
- } else {
234
- let map = new Map();
235
- for (let i = 0; i < token; i++) {
236
- map.set(read(), read());
237
- }
238
- return map
239
- }
240
- } else {
241
- token -= 0x90;
242
- let array = new Array(token);
243
- for (let i = 0; i < token; i++) {
244
- array[i] = read();
245
- }
246
- return array
247
- }
248
- } else if (token < 0xc0) {
249
- // fixstr
250
- let length = token - 0xa0;
251
- if (srcStringEnd >= position) {
252
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
253
- }
254
- if (srcStringEnd == 0 && srcEnd < 140) {
255
- // for small blocks, avoiding the overhead of the extract call is helpful
256
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
257
- if (string != null)
258
- return string
259
- }
260
- return readFixedString(length)
261
- } else {
262
- let value;
263
- switch (token) {
264
- case 0xc0: return null
265
- case 0xc1:
266
- if (bundledStrings) {
267
- value = read(); // followed by the length of the string in characters (not bytes!)
268
- if (value > 0)
269
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
270
- else
271
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
272
- }
273
- return C1; // "never-used", return special object to denote that
274
- case 0xc2: return false
275
- case 0xc3: return true
276
- case 0xc4:
277
- // bin 8
278
- return readBin(src[position++])
279
- case 0xc5:
280
- // bin 16
281
- value = dataView.getUint16(position);
282
- position += 2;
283
- return readBin(value)
284
- case 0xc6:
285
- // bin 32
286
- value = dataView.getUint32(position);
287
- position += 4;
288
- return readBin(value)
289
- case 0xc7:
290
- // ext 8
291
- return readExt(src[position++])
292
- case 0xc8:
293
- // ext 16
294
- value = dataView.getUint16(position);
295
- position += 2;
296
- return readExt(value)
297
- case 0xc9:
298
- // ext 32
299
- value = dataView.getUint32(position);
300
- position += 4;
301
- return readExt(value)
302
- case 0xca:
303
- value = dataView.getFloat32(position);
304
- if (currentUnpackr.useFloat32 > 2) {
305
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
306
- let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
307
- position += 4;
308
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
309
- }
310
- position += 4;
311
- return value
312
- case 0xcb:
313
- value = dataView.getFloat64(position);
314
- position += 8;
315
- return value
316
- // uint handlers
317
- case 0xcc:
318
- return src[position++]
319
- case 0xcd:
320
- value = dataView.getUint16(position);
321
- position += 2;
322
- return value
323
- case 0xce:
324
- value = dataView.getUint32(position);
325
- position += 4;
326
- return value
327
- case 0xcf:
328
- if (currentUnpackr.int64AsNumber) {
329
- value = dataView.getUint32(position) * 0x100000000;
330
- value += dataView.getUint32(position + 4);
331
- } else
332
- value = dataView.getBigUint64(position);
333
- position += 8;
334
- return value
335
-
336
- // int handlers
337
- case 0xd0:
338
- return dataView.getInt8(position++)
339
- case 0xd1:
340
- value = dataView.getInt16(position);
341
- position += 2;
342
- return value
343
- case 0xd2:
344
- value = dataView.getInt32(position);
345
- position += 4;
346
- return value
347
- case 0xd3:
348
- if (currentUnpackr.int64AsNumber) {
349
- value = dataView.getInt32(position) * 0x100000000;
350
- value += dataView.getUint32(position + 4);
351
- } else
352
- value = dataView.getBigInt64(position);
353
- position += 8;
354
- return value
355
-
356
- case 0xd4:
357
- // fixext 1
358
- value = src[position++];
359
- if (value == 0x72) {
360
- return recordDefinition(src[position++] & 0x3f)
361
- } else {
362
- let extension = currentExtensions[value];
363
- if (extension) {
364
- if (extension.read) {
365
- position++; // skip filler byte
366
- return extension.read(read())
367
- } else if (extension.noBuffer) {
368
- position++; // skip filler byte
369
- return extension()
370
- } else
371
- return extension(src.subarray(position, ++position))
372
- } else
373
- throw new Error('Unknown extension ' + value)
374
- }
375
- case 0xd5:
376
- // fixext 2
377
- value = src[position];
378
- if (value == 0x72) {
379
- position++;
380
- return recordDefinition(src[position++] & 0x3f, src[position++])
381
- } else
382
- return readExt(2)
383
- case 0xd6:
384
- // fixext 4
385
- return readExt(4)
386
- case 0xd7:
387
- // fixext 8
388
- return readExt(8)
389
- case 0xd8:
390
- // fixext 16
391
- return readExt(16)
392
- case 0xd9:
393
- // str 8
394
- value = src[position++];
395
- if (srcStringEnd >= position) {
396
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
397
- }
398
- return readString8(value)
399
- case 0xda:
400
- // str 16
401
- value = dataView.getUint16(position);
402
- position += 2;
403
- if (srcStringEnd >= position) {
404
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
405
- }
406
- return readString16(value)
407
- case 0xdb:
408
- // str 32
409
- value = dataView.getUint32(position);
410
- position += 4;
411
- if (srcStringEnd >= position) {
412
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
413
- }
414
- return readString32(value)
415
- case 0xdc:
416
- // array 16
417
- value = dataView.getUint16(position);
418
- position += 2;
419
- return readArray(value)
420
- case 0xdd:
421
- // array 32
422
- value = dataView.getUint32(position);
423
- position += 4;
424
- return readArray(value)
425
- case 0xde:
426
- // map 16
427
- value = dataView.getUint16(position);
428
- position += 2;
429
- return readMap(value)
430
- case 0xdf:
431
- // map 32
432
- value = dataView.getUint32(position);
433
- position += 4;
434
- return readMap(value)
435
- default: // negative int
436
- if (token >= 0xe0)
437
- return token - 0x100
438
- if (token === undefined) {
439
- let error = new Error('Unexpected end of MessagePack data');
440
- error.incomplete = true;
441
- throw error
442
- }
443
- throw new Error('Unknown MessagePack token ' + token)
444
-
445
- }
446
- }
447
- }
448
- const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
449
- function createStructureReader(structure, firstId) {
450
- function readObject() {
451
- // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
452
- if (readObject.count++ > inlineObjectReadThreshold) {
453
- let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
454
- if (structure.highByte === 0)
455
- structure.read = createSecondByteReader(firstId, structure.read);
456
- return readObject() // second byte is already read, if there is one so immediately read object
457
- }
458
- let object = {};
459
- for (let i = 0, l = structure.length; i < l; i++) {
460
- let key = structure[i];
461
- object[key] = read();
462
- }
463
- return object
464
- }
465
- readObject.count = 0;
466
- if (structure.highByte === 0) {
467
- return createSecondByteReader(firstId, readObject)
468
- }
469
- return readObject
470
- }
471
-
472
- const createSecondByteReader = (firstId, read0) => {
473
- return function() {
474
- let highByte = src[position++];
475
- if (highByte === 0)
476
- return read0()
477
- let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
478
- let structure = currentStructures[id] || loadStructures()[id];
479
- if (!structure) {
480
- throw new Error('Record id is not defined for ' + id)
481
- }
482
- if (!structure.read)
483
- structure.read = createStructureReader(structure, firstId);
484
- return structure.read()
485
- }
486
- };
487
-
488
- function loadStructures() {
489
- let loadedStructures = saveState(() => {
490
- // save the state in case getStructures modifies our buffer
491
- src = null;
492
- return currentUnpackr.getStructures()
493
- });
494
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
495
- }
496
-
497
- var readFixedString = readStringJS;
498
- var readString8 = readStringJS;
499
- var readString16 = readStringJS;
500
- var readString32 = readStringJS;
501
- exports.isNativeAccelerationEnabled = false;
502
-
503
- function setExtractor(extractStrings) {
504
- exports.isNativeAccelerationEnabled = true;
505
- readFixedString = readString(1);
506
- readString8 = readString(2);
507
- readString16 = readString(3);
508
- readString32 = readString(5);
509
- function readString(headerLength) {
510
- return function readString(length) {
511
- let string = strings[stringPosition++];
512
- if (string == null) {
513
- if (bundledStrings)
514
- return readStringJS(length)
515
- let extraction = extractStrings(position - headerLength, srcEnd, src);
516
- if (typeof extraction == 'string') {
517
- string = extraction;
518
- strings = EMPTY_ARRAY;
519
- } else {
520
- strings = extraction;
521
- stringPosition = 1;
522
- 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
523
- string = strings[0];
524
- if (string === undefined)
525
- throw new Error('Unexpected end of buffer')
526
- }
527
- }
528
- let srcStringLength = string.length;
529
- if (srcStringLength <= length) {
530
- position += length;
531
- return string
532
- }
533
- srcString = string;
534
- srcStringStart = position;
535
- srcStringEnd = position + srcStringLength;
536
- position += length;
537
- return string.slice(0, length) // we know we just want the beginning
538
- }
539
- }
540
- }
541
- function readStringJS(length) {
542
- let result;
543
- if (length < 16) {
544
- if (result = shortStringInJS(length))
545
- return result
546
- }
547
- if (length > 64 && decoder)
548
- return decoder.decode(src.subarray(position, position += length))
549
- const end = position + length;
550
- const units = [];
551
- result = '';
552
- while (position < end) {
553
- const byte1 = src[position++];
554
- if ((byte1 & 0x80) === 0) {
555
- // 1 byte
556
- units.push(byte1);
557
- } else if ((byte1 & 0xe0) === 0xc0) {
558
- // 2 bytes
559
- const byte2 = src[position++] & 0x3f;
560
- units.push(((byte1 & 0x1f) << 6) | byte2);
561
- } else if ((byte1 & 0xf0) === 0xe0) {
562
- // 3 bytes
563
- const byte2 = src[position++] & 0x3f;
564
- const byte3 = src[position++] & 0x3f;
565
- units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
566
- } else if ((byte1 & 0xf8) === 0xf0) {
567
- // 4 bytes
568
- const byte2 = src[position++] & 0x3f;
569
- const byte3 = src[position++] & 0x3f;
570
- const byte4 = src[position++] & 0x3f;
571
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
572
- if (unit > 0xffff) {
573
- unit -= 0x10000;
574
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
575
- unit = 0xdc00 | (unit & 0x3ff);
576
- }
577
- units.push(unit);
578
- } else {
579
- units.push(byte1);
580
- }
581
-
582
- if (units.length >= 0x1000) {
583
- result += fromCharCode.apply(String, units);
584
- units.length = 0;
585
- }
586
- }
587
-
588
- if (units.length > 0) {
589
- result += fromCharCode.apply(String, units);
590
- }
591
-
592
- return result
593
- }
594
-
595
- function readArray(length) {
596
- let array = new Array(length);
597
- for (let i = 0; i < length; i++) {
598
- array[i] = read();
599
- }
600
- return array
601
- }
602
-
603
- function readMap(length) {
604
- if (currentUnpackr.mapsAsObjects) {
605
- let object = {};
606
- for (let i = 0; i < length; i++) {
607
- object[readKey()] = read();
608
- }
609
- return object
610
- } else {
611
- let map = new Map();
612
- for (let i = 0; i < length; i++) {
613
- map.set(read(), read());
614
- }
615
- return map
616
- }
617
- }
618
-
619
- var fromCharCode = String.fromCharCode;
620
- function longStringInJS(length) {
621
- let start = position;
622
- let bytes = new Array(length);
623
- for (let i = 0; i < length; i++) {
624
- const byte = src[position++];
625
- if ((byte & 0x80) > 0) {
626
- position = start;
627
- return
628
- }
629
- bytes[i] = byte;
630
- }
631
- return fromCharCode.apply(String, bytes)
632
- }
633
- function shortStringInJS(length) {
634
- if (length < 4) {
635
- if (length < 2) {
636
- if (length === 0)
637
- return ''
638
- else {
639
- let a = src[position++];
640
- if ((a & 0x80) > 1) {
641
- position -= 1;
642
- return
643
- }
644
- return fromCharCode(a)
645
- }
646
- } else {
647
- let a = src[position++];
648
- let b = src[position++];
649
- if ((a & 0x80) > 0 || (b & 0x80) > 0) {
650
- position -= 2;
651
- return
652
- }
653
- if (length < 3)
654
- return fromCharCode(a, b)
655
- let c = src[position++];
656
- if ((c & 0x80) > 0) {
657
- position -= 3;
658
- return
659
- }
660
- return fromCharCode(a, b, c)
661
- }
662
- } else {
663
- let a = src[position++];
664
- let b = src[position++];
665
- let c = src[position++];
666
- let d = src[position++];
667
- if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
668
- position -= 4;
669
- return
670
- }
671
- if (length < 6) {
672
- if (length === 4)
673
- return fromCharCode(a, b, c, d)
674
- else {
675
- let e = src[position++];
676
- if ((e & 0x80) > 0) {
677
- position -= 5;
678
- return
679
- }
680
- return fromCharCode(a, b, c, d, e)
681
- }
682
- } else if (length < 8) {
683
- let e = src[position++];
684
- let f = src[position++];
685
- if ((e & 0x80) > 0 || (f & 0x80) > 0) {
686
- position -= 6;
687
- return
688
- }
689
- if (length < 7)
690
- return fromCharCode(a, b, c, d, e, f)
691
- let g = src[position++];
692
- if ((g & 0x80) > 0) {
693
- position -= 7;
694
- return
695
- }
696
- return fromCharCode(a, b, c, d, e, f, g)
697
- } else {
698
- let e = src[position++];
699
- let f = src[position++];
700
- let g = src[position++];
701
- let h = src[position++];
702
- if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
703
- position -= 8;
704
- return
705
- }
706
- if (length < 10) {
707
- if (length === 8)
708
- return fromCharCode(a, b, c, d, e, f, g, h)
709
- else {
710
- let i = src[position++];
711
- if ((i & 0x80) > 0) {
712
- position -= 9;
713
- return
714
- }
715
- return fromCharCode(a, b, c, d, e, f, g, h, i)
716
- }
717
- } else if (length < 12) {
718
- let i = src[position++];
719
- let j = src[position++];
720
- if ((i & 0x80) > 0 || (j & 0x80) > 0) {
721
- position -= 10;
722
- return
723
- }
724
- if (length < 11)
725
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
726
- let k = src[position++];
727
- if ((k & 0x80) > 0) {
728
- position -= 11;
729
- return
730
- }
731
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
732
- } else {
733
- let i = src[position++];
734
- let j = src[position++];
735
- let k = src[position++];
736
- let l = src[position++];
737
- if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
738
- position -= 12;
739
- return
740
- }
741
- if (length < 14) {
742
- if (length === 12)
743
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
744
- else {
745
- let m = src[position++];
746
- if ((m & 0x80) > 0) {
747
- position -= 13;
748
- return
749
- }
750
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
751
- }
752
- } else {
753
- let m = src[position++];
754
- let n = src[position++];
755
- if ((m & 0x80) > 0 || (n & 0x80) > 0) {
756
- position -= 14;
757
- return
758
- }
759
- if (length < 15)
760
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
761
- let o = src[position++];
762
- if ((o & 0x80) > 0) {
763
- position -= 15;
764
- return
765
- }
766
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
767
- }
768
- }
769
- }
770
- }
771
- }
772
-
773
- function readOnlyJSString() {
774
- let token = src[position++];
775
- let length;
776
- if (token < 0xc0) {
777
- // fixstr
778
- length = token - 0xa0;
779
- } else {
780
- switch(token) {
781
- case 0xd9:
782
- // str 8
783
- length = src[position++];
784
- break
785
- case 0xda:
786
- // str 16
787
- length = dataView.getUint16(position);
788
- position += 2;
789
- break
790
- case 0xdb:
791
- // str 32
792
- length = dataView.getUint32(position);
793
- position += 4;
794
- break
795
- default:
796
- throw new Error('Expected string')
797
- }
798
- }
799
- return readStringJS(length)
800
- }
801
-
802
-
803
- function readBin(length) {
804
- return currentUnpackr.copyBuffers ?
805
- // specifically use the copying slice (not the node one)
806
- Uint8Array.prototype.slice.call(src, position, position += length) :
807
- src.subarray(position, position += length)
808
- }
809
- function readExt(length) {
810
- let type = src[position++];
811
- if (currentExtensions[type]) {
812
- return currentExtensions[type](src.subarray(position, position += length))
813
- }
814
- else
815
- throw new Error('Unknown extension type ' + type)
816
- }
817
-
818
- var keyCache = new Array(4096);
819
- function readKey() {
820
- let length = src[position++];
821
- if (length >= 0xa0 && length < 0xc0) {
822
- // fixstr, potentially use key cache
823
- length = length - 0xa0;
824
- if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
825
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
826
- else if (!(srcStringEnd == 0 && srcEnd < 180))
827
- return readFixedString(length)
828
- } else { // not cacheable, go back and do a standard read
829
- position--;
830
- return read()
831
- }
832
- let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
833
- let entry = keyCache[key];
834
- let checkPosition = position;
835
- let end = position + length - 3;
836
- let chunk;
837
- let i = 0;
838
- if (entry && entry.bytes == length) {
839
- while (checkPosition < end) {
840
- chunk = dataView.getUint32(checkPosition);
841
- if (chunk != entry[i++]) {
842
- checkPosition = 0x70000000;
843
- break
844
- }
845
- checkPosition += 4;
846
- }
847
- end += 3;
848
- while (checkPosition < end) {
849
- chunk = src[checkPosition++];
850
- if (chunk != entry[i++]) {
851
- checkPosition = 0x70000000;
852
- break
853
- }
854
- }
855
- if (checkPosition === end) {
856
- position = checkPosition;
857
- return entry.string
858
- }
859
- end -= 3;
860
- checkPosition = position;
861
- }
862
- entry = [];
863
- keyCache[key] = entry;
864
- entry.bytes = length;
865
- while (checkPosition < end) {
866
- chunk = dataView.getUint32(checkPosition);
867
- entry.push(chunk);
868
- checkPosition += 4;
869
- }
870
- end += 3;
871
- while (checkPosition < end) {
872
- chunk = src[checkPosition++];
873
- entry.push(chunk);
874
- }
875
- // for small blocks, avoiding the overhead of the extract call is helpful
876
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
877
- if (string != null)
878
- return entry.string = string
879
- return entry.string = readFixedString(length)
880
- }
881
-
882
- // the registration of the record definition extension (as "r")
883
- const recordDefinition = (id, highByte) => {
884
- var structure = read();
885
- let firstByte = id;
886
- if (highByte !== undefined) {
887
- id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
888
- structure.highByte = highByte;
889
- }
890
- let existingStructure = currentStructures[id];
891
- if (existingStructure && existingStructure.isShared) {
892
- (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
893
- }
894
- currentStructures[id] = structure;
895
- structure.read = createStructureReader(structure, firstByte);
896
- return structure.read()
897
- };
898
- var glbl = typeof self == 'object' ? self : global;
899
- currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
900
- currentExtensions[0].noBuffer = true;
901
-
902
- currentExtensions[0x65] = () => {
903
- let data = read();
904
- return (glbl[data[0]] || Error)(data[1])
905
- };
906
-
907
- currentExtensions[0x69] = (data) => {
908
- // id extension (for structured clones)
909
- let id = dataView.getUint32(position - 4);
910
- if (!referenceMap)
911
- referenceMap = new Map();
912
- let token = src[position];
913
- let target;
914
- // TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
915
- // ahead past references to record structure definitions
916
- if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
917
- target = [];
918
- else
919
- target = {};
920
-
921
- let refEntry = { target }; // a placeholder object
922
- referenceMap.set(id, refEntry);
923
- let targetProperties = read(); // read the next value as the target object to id
924
- if (refEntry.used) // there is a cycle, so we have to assign properties to original target
925
- return Object.assign(target, targetProperties)
926
- refEntry.target = targetProperties; // the placeholder wasn't used, replace with the deserialized one
927
- return targetProperties // no cycle, can just use the returned read object
928
- };
929
-
930
- currentExtensions[0x70] = (data) => {
931
- // pointer extension (for structured clones)
932
- let id = dataView.getUint32(position - 4);
933
- let refEntry = referenceMap.get(id);
934
- refEntry.used = true;
935
- return refEntry.target
936
- };
937
-
938
- currentExtensions[0x73] = () => new Set(read());
939
-
940
- const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
941
-
942
- currentExtensions[0x74] = (data) => {
943
- let typeCode = data[0];
944
- let typedArrayName = typedArrays[typeCode];
945
- if (!typedArrayName)
946
- throw new Error('Could not find typed array for code ' + typeCode)
947
- // we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
948
- return new glbl[typedArrayName](Uint8Array.prototype.slice.call(data, 1).buffer)
949
- };
950
- currentExtensions[0x78] = () => {
951
- let data = read();
952
- return new RegExp(data[0], data[1])
953
- };
954
- const TEMP_BUNDLE = [];
955
- currentExtensions[0x62] = (data) => {
956
- let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
957
- let dataPosition = position;
958
- position += dataSize - data.length;
959
- bundledStrings = TEMP_BUNDLE;
960
- bundledStrings = [readOnlyJSString(), readOnlyJSString()];
961
- bundledStrings.position0 = 0;
962
- bundledStrings.position1 = 0;
963
- bundledStrings.postBundlePosition = position;
964
- position = dataPosition;
965
- return read()
966
- };
967
-
968
- currentExtensions[0xff] = (data) => {
969
- // 32-bit date extension
970
- if (data.length == 4)
971
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
972
- else if (data.length == 8)
973
- return new Date(
974
- ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
975
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
976
- else if (data.length == 12)// TODO: Implement support for negative
977
- return new Date(
978
- ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
979
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
980
- else
981
- return new Date('invalid')
982
- }; // notepack defines extension 0 to mean undefined, so use that as the default here
983
- // registration of bulk record definition?
984
- // currentExtensions[0x52] = () =>
985
-
986
- function saveState(callback) {
987
- let savedSrcEnd = srcEnd;
988
- let savedPosition = position;
989
- let savedStringPosition = stringPosition;
990
- let savedSrcStringStart = srcStringStart;
991
- let savedSrcStringEnd = srcStringEnd;
992
- let savedSrcString = srcString;
993
- let savedStrings = strings;
994
- let savedReferenceMap = referenceMap;
995
- let savedBundledStrings = bundledStrings;
996
-
997
- // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
998
- let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
999
- let savedStructures = currentStructures;
1000
- let savedStructuresContents = currentStructures.slice(0, currentStructures.length);
1001
- let savedPackr = currentUnpackr;
1002
- let savedSequentialMode = sequentialMode;
1003
- let value = callback();
1004
- srcEnd = savedSrcEnd;
1005
- position = savedPosition;
1006
- stringPosition = savedStringPosition;
1007
- srcStringStart = savedSrcStringStart;
1008
- srcStringEnd = savedSrcStringEnd;
1009
- srcString = savedSrcString;
1010
- strings = savedStrings;
1011
- referenceMap = savedReferenceMap;
1012
- bundledStrings = savedBundledStrings;
1013
- src = savedSrc;
1014
- sequentialMode = savedSequentialMode;
1015
- currentStructures = savedStructures;
1016
- currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1017
- currentUnpackr = savedPackr;
1018
- dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1019
- return value
1020
- }
1021
- function clearSource() {
1022
- src = null;
1023
- referenceMap = null;
1024
- currentStructures = null;
1025
- }
1026
-
1027
- function addExtension(extension) {
1028
- if (extension.unpack)
1029
- currentExtensions[extension.type] = extension.unpack;
1030
- else
1031
- currentExtensions[extension.type] = extension;
1032
- }
1033
-
1034
- const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1035
- for (let i = 0; i < 256; i++) {
1036
- mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
1037
- }
1038
- const Decoder = Unpackr;
1039
- var defaultUnpackr = new Unpackr({ useRecords: false });
1040
- const unpack = defaultUnpackr.unpack;
1041
- const unpackMultiple = defaultUnpackr.unpackMultiple;
1042
- const decode = defaultUnpackr.unpack;
1043
- const FLOAT32_OPTIONS = {
1044
- NEVER: 0,
1045
- ALWAYS: 1,
1046
- DECIMAL_ROUND: 3,
1047
- DECIMAL_FIT: 4
1048
- };
1049
- let f32Array = new Float32Array(1);
1050
- let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1051
- function roundFloat32(float32Number) {
1052
- f32Array[0] = float32Number;
1053
- let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1054
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
8
+ var decoder;
9
+ try {
10
+ decoder = new TextDecoder();
11
+ } catch(error) {}
12
+ var src;
13
+ var srcEnd;
14
+ var position = 0;
15
+ const EMPTY_ARRAY = [];
16
+ var strings = EMPTY_ARRAY;
17
+ var stringPosition = 0;
18
+ var currentUnpackr = {};
19
+ var currentStructures;
20
+ var srcString;
21
+ var srcStringStart = 0;
22
+ var srcStringEnd = 0;
23
+ var bundledStrings;
24
+ var referenceMap;
25
+ var currentExtensions = [];
26
+ var dataView;
27
+ var defaultOptions = {
28
+ useRecords: false,
29
+ mapsAsObjects: true
30
+ };
31
+ class C1Type {}
32
+ const C1 = new C1Type();
33
+ C1.name = 'MessagePack 0xC1';
34
+ var sequentialMode = false;
35
+ var inlineObjectReadThreshold = 2;
36
+ try {
37
+ new Function('');
38
+ } catch(error) {
39
+ // if eval variants are not supported, do not create inline object readers ever
40
+ inlineObjectReadThreshold = Infinity;
1055
41
  }
1056
42
 
1057
- let textEncoder;
1058
- try {
1059
- textEncoder = new TextEncoder();
1060
- } catch (error) {}
1061
- let extensions, extensionClasses;
1062
- const hasNodeBuffer = typeof Buffer !== 'undefined';
1063
- const ByteArrayAllocate = hasNodeBuffer ? Buffer.allocUnsafeSlow : Uint8Array;
1064
- const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1065
- const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1066
- let target, keysTarget;
1067
- let targetView;
1068
- let position$1 = 0;
1069
- let safeEnd;
1070
- let bundledStrings$1 = null;
1071
- const MAX_BUNDLE_SIZE = 0xf000;
1072
- const hasNonLatin = /[\u0080-\uFFFF]/;
1073
- const RECORD_SYMBOL = Symbol('record-id');
1074
- class Packr extends Unpackr {
1075
- constructor(options) {
1076
- super(options);
1077
- this.offset = 0;
1078
- let start;
1079
- let hasSharedUpdate;
1080
- let structures;
1081
- let referenceMap;
1082
- let lastSharedStructuresLength = 0;
1083
- let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position, maxBytes) {
1084
- return target.utf8Write(string, position, maxBytes)
1085
- } : (textEncoder && textEncoder.encodeInto) ?
1086
- function(string, position) {
1087
- return textEncoder.encodeInto(string, target.subarray(position)).written
1088
- } : false;
1089
-
1090
- let packr = this;
1091
- if (!options)
1092
- options = {};
1093
- let isSequential = options && options.sequential;
1094
- let hasSharedStructures = options.structures || options.saveStructures;
1095
- let maxSharedStructures = options.maxSharedStructures;
1096
- if (maxSharedStructures == null)
1097
- maxSharedStructures = hasSharedStructures ? 32 : 0;
1098
- if (maxSharedStructures > 8160)
1099
- throw new Error('Maximum maxSharedStructure is 8160')
1100
- if (options.structuredClone && options.moreTypes == undefined) {
1101
- options.moreTypes = true;
1102
- }
1103
- let maxOwnStructures = options.maxOwnStructures;
1104
- if (maxOwnStructures == null)
1105
- maxOwnStructures = hasSharedStructures ? 32 : 64;
1106
- if (!this.structures && options.useRecords != false)
1107
- this.structures = [];
1108
- // two byte record ids for shared structures
1109
- let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
1110
- let sharedLimitId = maxSharedStructures + 0x40;
1111
- let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1112
- if (maxStructureId > 8256) {
1113
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1114
- }
1115
- let recordIdsToRemove = [];
1116
- let transitionsCount = 0;
1117
- let serializationsSinceTransitionRebuild = 0;
1118
-
1119
- this.pack = this.encode = function(value, encodeOptions) {
1120
- if (!target) {
1121
- target = new ByteArrayAllocate(8192);
1122
- targetView = new DataView(target.buffer, 0, 8192);
1123
- position$1 = 0;
1124
- }
1125
- safeEnd = target.length - 10;
1126
- if (safeEnd - position$1 < 0x800) {
1127
- // don't start too close to the end,
1128
- target = new ByteArrayAllocate(target.length);
1129
- targetView = new DataView(target.buffer, 0, target.length);
1130
- safeEnd = target.length - 10;
1131
- position$1 = 0;
1132
- } else
1133
- position$1 = (position$1 + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1134
- start = position$1;
1135
- referenceMap = packr.structuredClone ? new Map() : null;
1136
- if (packr.bundleStrings && typeof value !== 'string') {
1137
- bundledStrings$1 = [];
1138
- bundledStrings$1.size = Infinity; // force a new bundle start on first string
1139
- } else
1140
- bundledStrings$1 = null;
1141
- structures = packr.structures;
1142
- if (structures) {
1143
- if (structures.uninitialized)
1144
- structures = packr._mergeStructures(packr.getStructures());
1145
- let sharedLength = structures.sharedLength || 0;
1146
- if (sharedLength > maxSharedStructures) {
1147
- //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1148
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1149
- }
1150
- if (!structures.transitions) {
1151
- // rebuild our structure transitions
1152
- structures.transitions = Object.create(null);
1153
- for (let i = 0; i < sharedLength; i++) {
1154
- let keys = structures[i];
1155
- if (!keys)
1156
- continue
1157
- let nextTransition, transition = structures.transitions;
1158
- for (let j = 0, l = keys.length; j < l; j++) {
1159
- let key = keys[j];
1160
- nextTransition = transition[key];
1161
- if (!nextTransition) {
1162
- nextTransition = transition[key] = Object.create(null);
1163
- }
1164
- transition = nextTransition;
1165
- }
1166
- transition[RECORD_SYMBOL] = i + 0x40;
1167
- }
1168
- lastSharedStructuresLength = sharedLength;
1169
- }
1170
- if (!isSequential) {
1171
- structures.nextId = sharedLength + 0x40;
1172
- }
1173
- }
1174
- if (hasSharedUpdate)
1175
- hasSharedUpdate = false;
1176
- try {
1177
- pack(value);
1178
- if (bundledStrings$1) {
1179
- writeBundles(start, pack);
1180
- }
1181
- packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1182
- if (referenceMap && referenceMap.idsToInsert) {
1183
- position$1 += referenceMap.idsToInsert.length * 6;
1184
- if (position$1 > safeEnd)
1185
- makeRoom(position$1);
1186
- packr.offset = position$1;
1187
- let serialized = insertIds(target.subarray(start, position$1), referenceMap.idsToInsert);
1188
- referenceMap = null;
1189
- return serialized
1190
- }
1191
- if (encodeOptions & REUSE_BUFFER_MODE) {
1192
- target.start = start;
1193
- target.end = position$1;
1194
- return target
1195
- }
1196
- return target.subarray(start, position$1) // position can change if we call pack again in saveStructures, so we get the buffer now
1197
- } finally {
1198
- if (structures) {
1199
- if (serializationsSinceTransitionRebuild < 10)
1200
- serializationsSinceTransitionRebuild++;
1201
- let sharedLength = structures.sharedLength || maxSharedStructures;
1202
- if (structures.length > sharedLength)
1203
- structures.length = sharedLength;
1204
- if (transitionsCount > 10000) {
1205
- // force a rebuild occasionally after a lot of transitions so it can get cleaned up
1206
- structures.transitions = null;
1207
- serializationsSinceTransitionRebuild = 0;
1208
- transitionsCount = 0;
1209
- if (recordIdsToRemove.length > 0)
1210
- recordIdsToRemove = [];
1211
- } else if (recordIdsToRemove.length > 0 && !isSequential) {
1212
- for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
1213
- recordIdsToRemove[i][RECORD_SYMBOL] = 0;
1214
- }
1215
- recordIdsToRemove = [];
1216
- }
1217
- if (hasSharedUpdate && packr.saveStructures) {
1218
- // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1219
- let returnBuffer = target.subarray(start, position$1);
1220
- if (packr.saveStructures(structures, lastSharedStructuresLength) === false) {
1221
- // get updated structures and try again if the update failed
1222
- packr._mergeStructures(packr.getStructures());
1223
- return packr.pack(value)
1224
- }
1225
- lastSharedStructuresLength = sharedLength;
1226
- return returnBuffer
1227
- }
1228
- }
1229
- if (encodeOptions & RESET_BUFFER_MODE)
1230
- position$1 = start;
1231
- }
1232
- };
1233
- const pack = (value) => {
1234
- if (position$1 > safeEnd)
1235
- target = makeRoom(position$1);
1236
-
1237
- var type = typeof value;
1238
- var length;
1239
- if (type === 'string') {
1240
- let strLength = value.length;
1241
- if (bundledStrings$1 && strLength >= 4 && strLength < 0x1000) {
1242
- if ((bundledStrings$1.size += strLength) > MAX_BUNDLE_SIZE) {
1243
- let extStart;
1244
- let maxBytes = (bundledStrings$1[0] ? bundledStrings$1[0].length * 3 + bundledStrings$1[1].length : 0) + 10;
1245
- if (position$1 + maxBytes > safeEnd)
1246
- target = makeRoom(position$1 + maxBytes);
1247
- if (bundledStrings$1.position) { // here we use the 0x62 extension to write the last bundle and reserve sapce for the reference pointer to the next/current bundle
1248
- target[position$1] = 0xc8; // ext 16
1249
- position$1 += 3; // reserve for the writing bundle size
1250
- target[position$1++] = 0x62; // 'b'
1251
- extStart = position$1 - start;
1252
- position$1 += 4; // reserve for writing bundle reference
1253
- writeBundles(start, pack); // write the last bundles
1254
- targetView.setUint16(extStart + start - 3, position$1 - start - extStart);
1255
- } else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
1256
- target[position$1++] = 0xd6; // fixext 4
1257
- target[position$1++] = 0x62; // 'b'
1258
- extStart = position$1 - start;
1259
- position$1 += 4; // reserve for writing bundle reference
1260
- }
1261
- bundledStrings$1 = ['', '']; // create new ones
1262
- bundledStrings$1.size = 0;
1263
- bundledStrings$1.position = extStart;
1264
- }
1265
- let twoByte = hasNonLatin.test(value);
1266
- bundledStrings$1[twoByte ? 0 : 1] += value;
1267
- target[position$1++] = 0xc1;
1268
- pack(twoByte ? -strLength : strLength);
1269
- return
1270
- }
1271
- let headerSize;
1272
- // first we estimate the header size, so we can write to the correct location
1273
- if (strLength < 0x20) {
1274
- headerSize = 1;
1275
- } else if (strLength < 0x100) {
1276
- headerSize = 2;
1277
- } else if (strLength < 0x10000) {
1278
- headerSize = 3;
1279
- } else {
1280
- headerSize = 5;
1281
- }
1282
- let maxBytes = strLength * 3;
1283
- if (position$1 + maxBytes > safeEnd)
1284
- target = makeRoom(position$1 + maxBytes);
1285
-
1286
- if (strLength < 0x40 || !encodeUtf8) {
1287
- let i, c1, c2, strPosition = position$1 + headerSize;
1288
- for (i = 0; i < strLength; i++) {
1289
- c1 = value.charCodeAt(i);
1290
- if (c1 < 0x80) {
1291
- target[strPosition++] = c1;
1292
- } else if (c1 < 0x800) {
1293
- target[strPosition++] = c1 >> 6 | 0xc0;
1294
- target[strPosition++] = c1 & 0x3f | 0x80;
1295
- } else if (
1296
- (c1 & 0xfc00) === 0xd800 &&
1297
- ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
1298
- ) {
1299
- c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
1300
- i++;
1301
- target[strPosition++] = c1 >> 18 | 0xf0;
1302
- target[strPosition++] = c1 >> 12 & 0x3f | 0x80;
1303
- target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
1304
- target[strPosition++] = c1 & 0x3f | 0x80;
1305
- } else {
1306
- target[strPosition++] = c1 >> 12 | 0xe0;
1307
- target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
1308
- target[strPosition++] = c1 & 0x3f | 0x80;
1309
- }
1310
- }
1311
- length = strPosition - position$1 - headerSize;
1312
- } else {
1313
- length = encodeUtf8(value, position$1 + headerSize, maxBytes);
1314
- }
1315
-
1316
- if (length < 0x20) {
1317
- target[position$1++] = 0xa0 | length;
1318
- } else if (length < 0x100) {
1319
- if (headerSize < 2) {
1320
- target.copyWithin(position$1 + 2, position$1 + 1, position$1 + 1 + length);
1321
- }
1322
- target[position$1++] = 0xd9;
1323
- target[position$1++] = length;
1324
- } else if (length < 0x10000) {
1325
- if (headerSize < 3) {
1326
- target.copyWithin(position$1 + 3, position$1 + 2, position$1 + 2 + length);
1327
- }
1328
- target[position$1++] = 0xda;
1329
- target[position$1++] = length >> 8;
1330
- target[position$1++] = length & 0xff;
1331
- } else {
1332
- if (headerSize < 5) {
1333
- target.copyWithin(position$1 + 5, position$1 + 3, position$1 + 3 + length);
1334
- }
1335
- target[position$1++] = 0xdb;
1336
- targetView.setUint32(position$1, length);
1337
- position$1 += 4;
1338
- }
1339
- position$1 += length;
1340
- } else if (type === 'number') {
1341
- if (value >>> 0 === value) {// positive integer, 32-bit or less
1342
- // positive uint
1343
- if (value < 0x40) {
1344
- target[position$1++] = value;
1345
- } else if (value < 0x100) {
1346
- target[position$1++] = 0xcc;
1347
- target[position$1++] = value;
1348
- } else if (value < 0x10000) {
1349
- target[position$1++] = 0xcd;
1350
- target[position$1++] = value >> 8;
1351
- target[position$1++] = value & 0xff;
1352
- } else {
1353
- target[position$1++] = 0xce;
1354
- targetView.setUint32(position$1, value);
1355
- position$1 += 4;
1356
- }
1357
- } else if (value >> 0 === value) { // negative integer
1358
- if (value >= -0x20) {
1359
- target[position$1++] = 0x100 + value;
1360
- } else if (value >= -0x80) {
1361
- target[position$1++] = 0xd0;
1362
- target[position$1++] = value + 0x100;
1363
- } else if (value >= -0x8000) {
1364
- target[position$1++] = 0xd1;
1365
- targetView.setInt16(position$1, value);
1366
- position$1 += 2;
1367
- } else {
1368
- target[position$1++] = 0xd2;
1369
- targetView.setInt32(position$1, value);
1370
- position$1 += 4;
1371
- }
1372
- } else {
1373
- let useFloat32;
1374
- if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
1375
- target[position$1++] = 0xca;
1376
- targetView.setFloat32(position$1, value);
1377
- let xShifted;
1378
- if (useFloat32 < 4 ||
1379
- // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1380
- ((xShifted = value * mult10[((target[position$1] & 0x7f) << 1) | (target[position$1 + 1] >> 7)]) >> 0) === xShifted) {
1381
- position$1 += 4;
1382
- return
1383
- } else
1384
- position$1--; // move back into position for writing a double
1385
- }
1386
- target[position$1++] = 0xcb;
1387
- targetView.setFloat64(position$1, value);
1388
- position$1 += 8;
1389
- }
1390
- } else if (type === 'object') {
1391
- if (!value)
1392
- target[position$1++] = 0xc0;
1393
- else {
1394
- if (referenceMap) {
1395
- let referee = referenceMap.get(value);
1396
- if (referee) {
1397
- if (!referee.id) {
1398
- let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
1399
- referee.id = idsToInsert.push(referee);
1400
- }
1401
- target[position$1++] = 0xd6; // fixext 4
1402
- target[position$1++] = 0x70; // "p" for pointer
1403
- targetView.setUint32(position$1, referee.id);
1404
- position$1 += 4;
1405
- return
1406
- } else
1407
- referenceMap.set(value, { offset: position$1 - start });
1408
- }
1409
- let constructor = value.constructor;
1410
- if (constructor === Object) {
1411
- writeObject(value, true);
1412
- } else if (constructor === Array) {
1413
- length = value.length;
1414
- if (length < 0x10) {
1415
- target[position$1++] = 0x90 | length;
1416
- } else if (length < 0x10000) {
1417
- target[position$1++] = 0xdc;
1418
- target[position$1++] = length >> 8;
1419
- target[position$1++] = length & 0xff;
1420
- } else {
1421
- target[position$1++] = 0xdd;
1422
- targetView.setUint32(position$1, length);
1423
- position$1 += 4;
1424
- }
1425
- for (let i = 0; i < length; i++) {
1426
- pack(value[i]);
1427
- }
1428
- } else if (constructor === Map) {
1429
- length = value.size;
1430
- if (length < 0x10) {
1431
- target[position$1++] = 0x80 | length;
1432
- } else if (length < 0x10000) {
1433
- target[position$1++] = 0xde;
1434
- target[position$1++] = length >> 8;
1435
- target[position$1++] = length & 0xff;
1436
- } else {
1437
- target[position$1++] = 0xdf;
1438
- targetView.setUint32(position$1, length);
1439
- position$1 += 4;
1440
- }
1441
- for (let [ key, entryValue ] of value) {
1442
- pack(key);
1443
- pack(entryValue);
1444
- }
1445
- } else {
1446
- for (let i = 0, l = extensions.length; i < l; i++) {
1447
- let extensionClass = extensionClasses[i];
1448
- if (value instanceof extensionClass) {
1449
- let extension = extensions[i];
1450
- if (extension.write) {
1451
- if (extension.type) {
1452
- target[position$1++] = 0xd4; // one byte "tag" extension
1453
- target[position$1++] = extension.type;
1454
- target[position$1++] = 0;
1455
- }
1456
- pack(extension.write.call(this, value));
1457
- return
1458
- }
1459
- let currentTarget = target;
1460
- let currentTargetView = targetView;
1461
- let currentPosition = position$1;
1462
- target = null;
1463
- let result;
1464
- try {
1465
- result = extension.pack.call(this, value, (size) => {
1466
- // restore target and use it
1467
- target = currentTarget;
1468
- currentTarget = null;
1469
- position$1 += size;
1470
- if (position$1 > safeEnd)
1471
- makeRoom(position$1);
1472
- return {
1473
- target, targetView, position: position$1 - size
1474
- }
1475
- }, pack);
1476
- } finally {
1477
- // restore current target information (unless already restored)
1478
- if (currentTarget) {
1479
- target = currentTarget;
1480
- targetView = currentTargetView;
1481
- position$1 = currentPosition;
1482
- safeEnd = target.length - 10;
1483
- }
1484
- }
1485
- if (result) {
1486
- if (result.length + position$1 > safeEnd)
1487
- makeRoom(result.length + position$1);
1488
- position$1 = writeExtensionData(result, target, position$1, extension.type);
1489
- }
1490
- return
1491
- }
1492
- }
1493
- // no extension found, write as object
1494
- writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
1495
- }
1496
- }
1497
- } else if (type === 'boolean') {
1498
- target[position$1++] = value ? 0xc3 : 0xc2;
1499
- } else if (type === 'bigint') {
1500
- if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
1501
- // use a signed int as long as it fits
1502
- target[position$1++] = 0xd3;
1503
- targetView.setBigInt64(position$1, value);
1504
- } else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
1505
- // if we can fit an unsigned int, use that
1506
- target[position$1++] = 0xcf;
1507
- targetView.setBigUint64(position$1, value);
1508
- } else {
1509
- // overflow
1510
- if (this.largeBigIntToFloat) {
1511
- target[position$1++] = 0xcb;
1512
- targetView.setFloat64(position$1, Number(value));
1513
- } else {
1514
- throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
1515
- }
1516
- }
1517
- position$1 += 8;
1518
- } else if (type === 'undefined') {
1519
- if (this.encodeUndefinedAsNil)
1520
- target[position$1++] = 0xc0;
1521
- else {
1522
- target[position$1++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1523
- target[position$1++] = 0;
1524
- target[position$1++] = 0;
1525
- }
1526
- } else if (type === 'function') {
1527
- pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
1528
- } else {
1529
- throw new Error('Unknown type: ' + type)
1530
- }
1531
- };
1532
-
1533
- const writeObject = this.useRecords === false ? this.variableMapSize ? (object) => {
1534
- // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
1535
- let keys = Object.keys(object);
1536
- let length = keys.length;
1537
- if (length < 0x10) {
1538
- target[position$1++] = 0x80 | length;
1539
- } else if (length < 0x10000) {
1540
- target[position$1++] = 0xde;
1541
- target[position$1++] = length >> 8;
1542
- target[position$1++] = length & 0xff;
1543
- } else {
1544
- target[position$1++] = 0xdf;
1545
- targetView.setUint32(position$1, length);
1546
- position$1 += 4;
1547
- }
1548
- let key;
1549
- for (let i = 0; i < length; i++) {
1550
- pack(key = keys[i]);
1551
- pack(object[key]);
1552
- }
1553
- } :
1554
- (object, safePrototype) => {
1555
- target[position$1++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1556
- let objectOffset = position$1 - start;
1557
- position$1 += 2;
1558
- let size = 0;
1559
- for (let key in object) {
1560
- if (safePrototype || object.hasOwnProperty(key)) {
1561
- pack(key);
1562
- pack(object[key]);
1563
- size++;
1564
- }
1565
- }
1566
- target[objectOffset++ + start] = size >> 8;
1567
- target[objectOffset + start] = size & 0xff;
1568
- } :
1569
- (options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
1570
- (object, safePrototype) => {
1571
- let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1572
- let objectOffset = position$1++ - start;
1573
- let wroteKeys;
1574
- for (let key in object) {
1575
- if (safePrototype || object.hasOwnProperty(key)) {
1576
- nextTransition = transition[key];
1577
- if (nextTransition)
1578
- transition = nextTransition;
1579
- else {
1580
- // record doesn't exist, create full new record and insert it
1581
- let keys = Object.keys(object);
1582
- let lastTransition = transition;
1583
- transition = structures.transitions;
1584
- let newTransitions = 0;
1585
- for (let i = 0, l = keys.length; i < l; i++) {
1586
- let key = keys[i];
1587
- nextTransition = transition[key];
1588
- if (!nextTransition) {
1589
- nextTransition = transition[key] = Object.create(null);
1590
- newTransitions++;
1591
- }
1592
- transition = nextTransition;
1593
- }
1594
- if (objectOffset + start + 1 == position$1) {
1595
- // first key, so we don't need to insert, we can just write record directly
1596
- position$1--;
1597
- newRecord(transition, keys, newTransitions);
1598
- } else // otherwise we need to insert the record, moving existing data after the record
1599
- insertNewRecord(transition, keys, objectOffset, newTransitions);
1600
- wroteKeys = true;
1601
- transition = lastTransition[key];
1602
- }
1603
- pack(object[key]);
1604
- }
1605
- }
1606
- if (!wroteKeys) {
1607
- let recordId = transition[RECORD_SYMBOL];
1608
- if (recordId)
1609
- target[objectOffset + start] = recordId;
1610
- else
1611
- insertNewRecord(transition, Object.keys(object), objectOffset, 0);
1612
- }
1613
- } :
1614
- (object, safePrototype) => {
1615
- let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1616
- let newTransitions = 0;
1617
- for (let key in object) if (safePrototype || object.hasOwnProperty(key)) {
1618
- nextTransition = transition[key];
1619
- if (!nextTransition) {
1620
- nextTransition = transition[key] = Object.create(null);
1621
- newTransitions++;
1622
- }
1623
- transition = nextTransition;
1624
- }
1625
- let recordId = transition[RECORD_SYMBOL];
1626
- if (recordId) {
1627
- if (recordId >= 0x60 && useTwoByteRecords) {
1628
- target[position$1++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1629
- target[position$1++] = recordId >> 5;
1630
- } else
1631
- target[position$1++] = recordId;
1632
- } else {
1633
- newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
1634
- }
1635
- // now write the values
1636
- for (let key in object)
1637
- if (safePrototype || object.hasOwnProperty(key))
1638
- pack(object[key]);
1639
- };
1640
- const makeRoom = (end) => {
1641
- let newSize;
1642
- if (end > 0x1000000) {
1643
- // special handling for really large buffers
1644
- if ((end - start) > MAX_BUFFER_SIZE)
1645
- throw new Error('Packed buffer would be larger than maximum buffer size')
1646
- newSize = Math.min(MAX_BUFFER_SIZE,
1647
- Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1648
- } else // faster handling for smaller buffers
1649
- newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
1650
- let newBuffer = new ByteArrayAllocate(newSize);
1651
- targetView = new DataView(newBuffer.buffer, 0, newSize);
1652
- if (target.copy)
1653
- target.copy(newBuffer, 0, start, end);
1654
- else
1655
- newBuffer.set(target.slice(start, end));
1656
- position$1 -= start;
1657
- start = 0;
1658
- safeEnd = newBuffer.length - 10;
1659
- return target = newBuffer
1660
- };
1661
- const newRecord = (transition, keys, newTransitions) => {
1662
- let recordId = structures.nextId;
1663
- if (!recordId)
1664
- recordId = 0x40;
1665
- if (recordId < sharedLimitId && this.shouldShareStructure && !this.shouldShareStructure(keys)) {
1666
- recordId = structures.nextOwnId;
1667
- if (!(recordId < maxStructureId))
1668
- recordId = sharedLimitId;
1669
- structures.nextOwnId = recordId + 1;
1670
- } else {
1671
- if (recordId >= maxStructureId)// cycle back around
1672
- recordId = sharedLimitId;
1673
- structures.nextId = recordId + 1;
1674
- }
1675
- let highByte = keys.highByte = recordId >= 0x60 && useTwoByteRecords ? (recordId - 0x60) >> 5 : -1;
1676
- transition[RECORD_SYMBOL] = recordId;
1677
- transition.__keys__ = keys;
1678
- structures[recordId - 0x40] = keys;
1679
-
1680
- if (recordId < sharedLimitId) {
1681
- keys.isShared = true;
1682
- structures.sharedLength = recordId - 0x3f;
1683
- hasSharedUpdate = true;
1684
- if (highByte >= 0) {
1685
- target[position$1++] = (recordId & 0x1f) + 0x60;
1686
- target[position$1++] = highByte;
1687
- } else {
1688
- target[position$1++] = recordId;
1689
- }
1690
- } else {
1691
- if (highByte >= 0) {
1692
- target[position$1++] = 0xd5; // fixext 2
1693
- target[position$1++] = 0x72; // "r" record defintion extension type
1694
- target[position$1++] = (recordId & 0x1f) + 0x60;
1695
- target[position$1++] = highByte;
1696
- } else {
1697
- target[position$1++] = 0xd4; // fixext 1
1698
- target[position$1++] = 0x72; // "r" record defintion extension type
1699
- target[position$1++] = recordId;
1700
- }
1701
-
1702
- if (newTransitions)
1703
- transitionsCount += serializationsSinceTransitionRebuild * newTransitions;
1704
- // record the removal of the id, we can maintain our shared structure
1705
- if (recordIdsToRemove.length >= maxOwnStructures)
1706
- recordIdsToRemove.shift()[RECORD_SYMBOL] = 0; // we are cycling back through, and have to remove old ones
1707
- recordIdsToRemove.push(transition);
1708
- pack(keys);
1709
- }
1710
- };
1711
- const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
1712
- let mainTarget = target;
1713
- let mainPosition = position$1;
1714
- let mainSafeEnd = safeEnd;
1715
- let mainStart = start;
1716
- target = keysTarget;
1717
- position$1 = 0;
1718
- start = 0;
1719
- if (!target)
1720
- keysTarget = target = new ByteArrayAllocate(8192);
1721
- safeEnd = target.length - 10;
1722
- newRecord(transition, keys, newTransitions);
1723
- keysTarget = target;
1724
- let keysPosition = position$1;
1725
- target = mainTarget;
1726
- position$1 = mainPosition;
1727
- safeEnd = mainSafeEnd;
1728
- start = mainStart;
1729
- if (keysPosition > 1) {
1730
- let newEnd = position$1 + keysPosition - 1;
1731
- if (newEnd > safeEnd)
1732
- makeRoom(newEnd);
1733
- let insertionPosition = insertionOffset + start;
1734
- target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position$1);
1735
- target.set(keysTarget.slice(0, keysPosition), insertionPosition);
1736
- position$1 = newEnd;
1737
- } else {
1738
- target[insertionOffset + start] = keysTarget[0];
1739
- }
1740
- };
1741
- }
1742
- useBuffer(buffer) {
1743
- // this means we are finished using our own buffer and we can write over it safely
1744
- target = buffer;
1745
- targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
1746
- position$1 = 0;
1747
- }
1748
- clearSharedData() {
1749
- if (this.structures)
1750
- this.structures = [];
1751
- }
1752
- }
1753
-
1754
- extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/, C1Type ];
1755
- extensions = [{
1756
- pack(date, allocateForWrite, pack) {
1757
- let seconds = date.getTime() / 1000;
1758
- if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
1759
- // Timestamp 32
1760
- let { target, targetView, position} = allocateForWrite(6);
1761
- target[position++] = 0xd6;
1762
- target[position++] = 0xff;
1763
- targetView.setUint32(position, seconds);
1764
- } else if (seconds > 0 && seconds < 0x400000000) {
1765
- // Timestamp 64
1766
- let { target, targetView, position} = allocateForWrite(10);
1767
- target[position++] = 0xd7;
1768
- target[position++] = 0xff;
1769
- targetView.setUint32(position, date.getMilliseconds() * 4000000 + ((seconds / 1000 / 0x100000000) >> 0));
1770
- targetView.setUint32(position + 4, seconds);
1771
- } else if (isNaN(seconds)) {
1772
- if (this.onInvalidDate) {
1773
- allocateForWrite(0);
1774
- return pack(this.onInvalidDate())
1775
- }
1776
- // Intentionally invalid timestamp
1777
- let { target, targetView, position} = allocateForWrite(3);
1778
- target[position++] = 0xd4;
1779
- target[position++] = 0xff;
1780
- target[position++] = 0xff;
1781
- } else {
1782
- // Timestamp 96
1783
- let { target, targetView, position} = allocateForWrite(15);
1784
- target[position++] = 0xc7;
1785
- target[position++] = 12;
1786
- target[position++] = 0xff;
1787
- targetView.setUint32(position, date.getMilliseconds() * 1000000);
1788
- targetView.setBigInt64(position + 4, BigInt(Math.floor(seconds)));
1789
- }
1790
- }
1791
- }, {
1792
- pack(set, allocateForWrite, pack) {
1793
- let array = Array.from(set);
1794
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1795
- if (this.moreTypes) {
1796
- target[position++] = 0xd4;
1797
- target[position++] = 0x73; // 's' for Set
1798
- target[position++] = 0;
1799
- }
1800
- pack(array);
1801
- }
1802
- }, {
1803
- pack(error, allocateForWrite, pack) {
1804
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1805
- if (this.moreTypes) {
1806
- target[position++] = 0xd4;
1807
- target[position++] = 0x65; // 'e' for error
1808
- target[position++] = 0;
1809
- }
1810
- pack([ error.name, error.message ]);
1811
- }
1812
- }, {
1813
- pack(regex, allocateForWrite, pack) {
1814
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1815
- if (this.moreTypes) {
1816
- target[position++] = 0xd4;
1817
- target[position++] = 0x78; // 'x' for regeXp
1818
- target[position++] = 0;
1819
- }
1820
- pack([ regex.source, regex.flags ]);
1821
- }
1822
- }, {
1823
- pack(arrayBuffer, allocateForWrite) {
1824
- if (this.moreTypes)
1825
- writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
1826
- else
1827
- writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
1828
- }
1829
- }, {
1830
- pack(typedArray, allocateForWrite) {
1831
- let constructor = typedArray.constructor;
1832
- if (constructor !== ByteArray && this.moreTypes)
1833
- writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
1834
- else
1835
- writeBuffer(typedArray, allocateForWrite);
1836
- }
1837
- }, {
1838
- pack(c1, allocateForWrite) { // specific 0xC1 object
1839
- let { target, position} = allocateForWrite(1);
1840
- target[position] = 0xc1;
1841
- }
1842
- }];
1843
-
1844
- function writeExtBuffer(typedArray, type, allocateForWrite, encode) {
1845
- let length = typedArray.byteLength;
1846
- if (length + 1 < 0x100) {
1847
- var { target, position } = allocateForWrite(4 + length);
1848
- target[position++] = 0xc7;
1849
- target[position++] = length + 1;
1850
- } else if (length + 1 < 0x10000) {
1851
- var { target, position } = allocateForWrite(5 + length);
1852
- target[position++] = 0xc8;
1853
- target[position++] = (length + 1) >> 8;
1854
- target[position++] = (length + 1) & 0xff;
1855
- } else {
1856
- var { target, position, targetView } = allocateForWrite(7 + length);
1857
- target[position++] = 0xc9;
1858
- targetView.setUint32(position, length + 1); // plus one for the type byte
1859
- position += 4;
1860
- }
1861
- target[position++] = 0x74; // "t" for typed array
1862
- target[position++] = type;
1863
- target.set(new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength), position);
1864
- }
1865
- function writeBuffer(buffer, allocateForWrite) {
1866
- let length = buffer.byteLength;
1867
- var target, position;
1868
- if (length < 0x100) {
1869
- var { target, position } = allocateForWrite(length + 2);
1870
- target[position++] = 0xc4;
1871
- target[position++] = length;
1872
- } else if (length < 0x10000) {
1873
- var { target, position } = allocateForWrite(length + 3);
1874
- target[position++] = 0xc5;
1875
- target[position++] = length >> 8;
1876
- target[position++] = length & 0xff;
1877
- } else {
1878
- var { target, position, targetView } = allocateForWrite(length + 5);
1879
- target[position++] = 0xc6;
1880
- targetView.setUint32(position, length);
1881
- position += 4;
1882
- }
1883
- target.set(buffer, position);
1884
- }
1885
-
1886
- function writeExtensionData(result, target, position, type) {
1887
- let length = result.length;
1888
- switch (length) {
1889
- case 1:
1890
- target[position++] = 0xd4;
1891
- break
1892
- case 2:
1893
- target[position++] = 0xd5;
1894
- break
1895
- case 4:
1896
- target[position++] = 0xd6;
1897
- break
1898
- case 8:
1899
- target[position++] = 0xd7;
1900
- break
1901
- case 16:
1902
- target[position++] = 0xd8;
1903
- break
1904
- default:
1905
- if (length < 0x100) {
1906
- target[position++] = 0xc7;
1907
- target[position++] = length;
1908
- } else if (length < 0x10000) {
1909
- target[position++] = 0xc8;
1910
- target[position++] = length >> 8;
1911
- target[position++] = length & 0xff;
1912
- } else {
1913
- target[position++] = 0xc9;
1914
- target[position++] = length >> 24;
1915
- target[position++] = (length >> 16) & 0xff;
1916
- target[position++] = (length >> 8) & 0xff;
1917
- target[position++] = length & 0xff;
1918
- }
1919
- }
1920
- target[position++] = type;
1921
- target.set(result, position);
1922
- position += length;
1923
- return position
1924
- }
1925
-
1926
- function insertIds(serialized, idsToInsert) {
1927
- // insert the ids that need to be referenced for structured clones
1928
- let nextId;
1929
- let distanceToMove = idsToInsert.length * 6;
1930
- let lastEnd = serialized.length - distanceToMove;
1931
- idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
1932
- while (nextId = idsToInsert.pop()) {
1933
- let offset = nextId.offset;
1934
- let id = nextId.id;
1935
- serialized.copyWithin(offset + distanceToMove, offset, lastEnd);
1936
- distanceToMove -= 6;
1937
- let position = offset + distanceToMove;
1938
- serialized[position++] = 0xd6;
1939
- serialized[position++] = 0x69; // 'i'
1940
- serialized[position++] = id >> 24;
1941
- serialized[position++] = (id >> 16) & 0xff;
1942
- serialized[position++] = (id >> 8) & 0xff;
1943
- serialized[position++] = id & 0xff;
1944
- lastEnd = offset;
1945
- }
1946
- return serialized
1947
- }
1948
-
1949
- function writeBundles(start, pack) {
1950
- targetView.setUint32(bundledStrings$1.position + start, position$1 - bundledStrings$1.position - start);
1951
- let writeStrings = bundledStrings$1;
1952
- bundledStrings$1 = null;
1953
- pack(writeStrings[0]);
1954
- pack(writeStrings[1]);
1955
- }
1956
-
1957
- function addExtension$1(extension) {
1958
- if (extension.Class) {
1959
- if (!extension.pack && !extension.write)
1960
- throw new Error('Extension has no pack or write function')
1961
- if (extension.pack && !extension.type)
1962
- throw new Error('Extension has no type (numeric code to identify the extension)')
1963
- extensionClasses.unshift(extension.Class);
1964
- extensions.unshift(extension);
1965
- }
1966
- addExtension(extension);
1967
- }
1968
-
1969
- let defaultPackr = new Packr({ useRecords: false });
1970
- const pack = defaultPackr.pack;
1971
- const encode = defaultPackr.pack;
1972
- const Encoder = Packr;
1973
- const { NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = FLOAT32_OPTIONS;
1974
- const REUSE_BUFFER_MODE = 512;
43
+ class Unpackr {
44
+ constructor(options) {
45
+ if (options) {
46
+ if (options.useRecords === false && options.mapsAsObjects === undefined)
47
+ options.mapsAsObjects = true;
48
+ if (options.sequential && options.trusted !== false) {
49
+ options.trusted = true;
50
+ if (!options.structures && options.useRecords != false) {
51
+ options.structures = [];
52
+ if (!options.maxSharedStructures)
53
+ options.maxSharedStructures = 0;
54
+ }
55
+ }
56
+ if (options.structures)
57
+ options.structures.sharedLength = options.structures.length;
58
+ else if (options.getStructures) {
59
+ (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
60
+ options.structures.sharedLength = 0;
61
+ }
62
+ }
63
+ Object.assign(this, options);
64
+ }
65
+ unpack(source, end) {
66
+ if (src) {
67
+ // re-entrant execution, save the state and restore it after we do this unpack
68
+ return saveState(() => {
69
+ clearSource();
70
+ return this ? this.unpack(source, end) : Unpackr.prototype.unpack.call(defaultOptions, source, end)
71
+ })
72
+ }
73
+ srcEnd = end > -1 ? end : source.length;
74
+ position = 0;
75
+ stringPosition = 0;
76
+ srcStringEnd = 0;
77
+ srcString = null;
78
+ strings = EMPTY_ARRAY;
79
+ bundledStrings = null;
80
+ src = source;
81
+ // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
82
+ // technique for getting data from a database where it can be copied into an existing buffer instead of creating
83
+ // new ones
84
+ try {
85
+ dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
86
+ } catch(error) {
87
+ // if it doesn't have a buffer, maybe it is the wrong type of object
88
+ src = null;
89
+ if (source instanceof Uint8Array)
90
+ throw error
91
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
92
+ }
93
+ if (this instanceof Unpackr) {
94
+ currentUnpackr = this;
95
+ if (this.structures) {
96
+ currentStructures = this.structures;
97
+ return checkedRead()
98
+ } else if (!currentStructures || currentStructures.length > 0) {
99
+ currentStructures = [];
100
+ }
101
+ } else {
102
+ currentUnpackr = defaultOptions;
103
+ if (!currentStructures || currentStructures.length > 0)
104
+ currentStructures = [];
105
+ }
106
+ return checkedRead()
107
+ }
108
+ unpackMultiple(source, forEach) {
109
+ let values, lastPosition = 0;
110
+ try {
111
+ sequentialMode = true;
112
+ let size = source.length;
113
+ let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
114
+ if (forEach) {
115
+ forEach(value);
116
+ while(position < size) {
117
+ lastPosition = position;
118
+ if (forEach(checkedRead()) === false) {
119
+ return
120
+ }
121
+ }
122
+ }
123
+ else {
124
+ values = [ value ];
125
+ while(position < size) {
126
+ lastPosition = position;
127
+ values.push(checkedRead());
128
+ }
129
+ return values
130
+ }
131
+ } catch(error) {
132
+ error.lastPosition = lastPosition;
133
+ error.values = values;
134
+ throw error
135
+ } finally {
136
+ sequentialMode = false;
137
+ clearSource();
138
+ }
139
+ }
140
+ _mergeStructures(loadedStructures, existingStructures) {
141
+ loadedStructures = loadedStructures || [];
142
+ for (let i = 0, l = loadedStructures.length; i < l; i++) {
143
+ let structure = loadedStructures[i];
144
+ if (structure) {
145
+ structure.isShared = true;
146
+ if (i >= 32)
147
+ structure.highByte = (i - 32) >> 5;
148
+ }
149
+ }
150
+ loadedStructures.sharedLength = loadedStructures.length;
151
+ for (let id in existingStructures || []) {
152
+ if (id >= 0) {
153
+ let structure = loadedStructures[id];
154
+ let existing = existingStructures[id];
155
+ if (existing) {
156
+ if (structure)
157
+ (loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure;
158
+ loadedStructures[id] = existing;
159
+ }
160
+ }
161
+ }
162
+ return this.structures = loadedStructures
163
+ }
164
+ decode(source, end) {
165
+ return this.unpack(source, end)
166
+ }
167
+ }
168
+ function checkedRead() {
169
+ try {
170
+ if (!currentUnpackr.trusted && !sequentialMode) {
171
+ let sharedLength = currentStructures.sharedLength || 0;
172
+ if (sharedLength < currentStructures.length)
173
+ currentStructures.length = sharedLength;
174
+ }
175
+ let result = read();
176
+ if (bundledStrings) // bundled strings to skip past
177
+ position = bundledStrings.postBundlePosition;
178
+
179
+ if (position == srcEnd) {
180
+ // finished reading this source, cleanup references
181
+ if (currentStructures.restoreStructures)
182
+ restoreStructures();
183
+ currentStructures = null;
184
+ src = null;
185
+ if (referenceMap)
186
+ referenceMap = null;
187
+ } else if (position > srcEnd) {
188
+ // over read
189
+ throw new Error('Unexpected end of MessagePack data')
190
+ } else if (!sequentialMode) {
191
+ throw new Error('Data read, but end of buffer not reached ' + JSON.stringify(result).slice(0, 100))
192
+ }
193
+ // else more to read, but we are reading sequentially, so don't clear source yet
194
+ return result
195
+ } catch(error) {
196
+ if (currentStructures.restoreStructures)
197
+ restoreStructures();
198
+ clearSource();
199
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
200
+ error.incomplete = true;
201
+ }
202
+ throw error
203
+ }
204
+ }
205
+
206
+ function restoreStructures() {
207
+ for (let id in currentStructures.restoreStructures) {
208
+ currentStructures[id] = currentStructures.restoreStructures[id];
209
+ }
210
+ currentStructures.restoreStructures = null;
211
+ }
212
+
213
+ function read() {
214
+ let token = src[position++];
215
+ if (token < 0xa0) {
216
+ if (token < 0x80) {
217
+ if (token < 0x40)
218
+ return token
219
+ else {
220
+ let structure = currentStructures[token & 0x3f] ||
221
+ currentUnpackr.getStructures && loadStructures()[token & 0x3f];
222
+ if (structure) {
223
+ if (!structure.read) {
224
+ structure.read = createStructureReader(structure, token & 0x3f);
225
+ }
226
+ return structure.read()
227
+ } else
228
+ return token
229
+ }
230
+ } else if (token < 0x90) {
231
+ // map
232
+ token -= 0x80;
233
+ if (currentUnpackr.mapsAsObjects) {
234
+ let object = {};
235
+ for (let i = 0; i < token; i++) {
236
+ object[readKey()] = read();
237
+ }
238
+ return object
239
+ } else {
240
+ let map = new Map();
241
+ for (let i = 0; i < token; i++) {
242
+ map.set(read(), read());
243
+ }
244
+ return map
245
+ }
246
+ } else {
247
+ token -= 0x90;
248
+ let array = new Array(token);
249
+ for (let i = 0; i < token; i++) {
250
+ array[i] = read();
251
+ }
252
+ return array
253
+ }
254
+ } else if (token < 0xc0) {
255
+ // fixstr
256
+ let length = token - 0xa0;
257
+ if (srcStringEnd >= position) {
258
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
259
+ }
260
+ if (srcStringEnd == 0 && srcEnd < 140) {
261
+ // for small blocks, avoiding the overhead of the extract call is helpful
262
+ let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
263
+ if (string != null)
264
+ return string
265
+ }
266
+ return readFixedString(length)
267
+ } else {
268
+ let value;
269
+ switch (token) {
270
+ case 0xc0: return null
271
+ case 0xc1:
272
+ if (bundledStrings) {
273
+ value = read(); // followed by the length of the string in characters (not bytes!)
274
+ if (value > 0)
275
+ return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
276
+ else
277
+ return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
278
+ }
279
+ return C1; // "never-used", return special object to denote that
280
+ case 0xc2: return false
281
+ case 0xc3: return true
282
+ case 0xc4:
283
+ // bin 8
284
+ value = src[position++];
285
+ if (value === undefined)
286
+ throw new Error('Unexpected end of buffer')
287
+ return readBin(value)
288
+ case 0xc5:
289
+ // bin 16
290
+ value = dataView.getUint16(position);
291
+ position += 2;
292
+ return readBin(value)
293
+ case 0xc6:
294
+ // bin 32
295
+ value = dataView.getUint32(position);
296
+ position += 4;
297
+ return readBin(value)
298
+ case 0xc7:
299
+ // ext 8
300
+ return readExt(src[position++])
301
+ case 0xc8:
302
+ // ext 16
303
+ value = dataView.getUint16(position);
304
+ position += 2;
305
+ return readExt(value)
306
+ case 0xc9:
307
+ // ext 32
308
+ value = dataView.getUint32(position);
309
+ position += 4;
310
+ return readExt(value)
311
+ case 0xca:
312
+ value = dataView.getFloat32(position);
313
+ if (currentUnpackr.useFloat32 > 2) {
314
+ // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
315
+ let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
316
+ position += 4;
317
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
318
+ }
319
+ position += 4;
320
+ return value
321
+ case 0xcb:
322
+ value = dataView.getFloat64(position);
323
+ position += 8;
324
+ return value
325
+ // uint handlers
326
+ case 0xcc:
327
+ return src[position++]
328
+ case 0xcd:
329
+ value = dataView.getUint16(position);
330
+ position += 2;
331
+ return value
332
+ case 0xce:
333
+ value = dataView.getUint32(position);
334
+ position += 4;
335
+ return value
336
+ case 0xcf:
337
+ if (currentUnpackr.int64AsNumber) {
338
+ value = dataView.getUint32(position) * 0x100000000;
339
+ value += dataView.getUint32(position + 4);
340
+ } else
341
+ value = dataView.getBigUint64(position);
342
+ position += 8;
343
+ return value
344
+
345
+ // int handlers
346
+ case 0xd0:
347
+ return dataView.getInt8(position++)
348
+ case 0xd1:
349
+ value = dataView.getInt16(position);
350
+ position += 2;
351
+ return value
352
+ case 0xd2:
353
+ value = dataView.getInt32(position);
354
+ position += 4;
355
+ return value
356
+ case 0xd3:
357
+ if (currentUnpackr.int64AsNumber) {
358
+ value = dataView.getInt32(position) * 0x100000000;
359
+ value += dataView.getUint32(position + 4);
360
+ } else
361
+ value = dataView.getBigInt64(position);
362
+ position += 8;
363
+ return value
364
+
365
+ case 0xd4:
366
+ // fixext 1
367
+ value = src[position++];
368
+ if (value == 0x72) {
369
+ return recordDefinition(src[position++] & 0x3f)
370
+ } else {
371
+ let extension = currentExtensions[value];
372
+ if (extension) {
373
+ if (extension.read) {
374
+ position++; // skip filler byte
375
+ return extension.read(read())
376
+ } else if (extension.noBuffer) {
377
+ position++; // skip filler byte
378
+ return extension()
379
+ } else
380
+ return extension(src.subarray(position, ++position))
381
+ } else
382
+ throw new Error('Unknown extension ' + value)
383
+ }
384
+ case 0xd5:
385
+ // fixext 2
386
+ value = src[position];
387
+ if (value == 0x72) {
388
+ position++;
389
+ return recordDefinition(src[position++] & 0x3f, src[position++])
390
+ } else
391
+ return readExt(2)
392
+ case 0xd6:
393
+ // fixext 4
394
+ return readExt(4)
395
+ case 0xd7:
396
+ // fixext 8
397
+ return readExt(8)
398
+ case 0xd8:
399
+ // fixext 16
400
+ return readExt(16)
401
+ case 0xd9:
402
+ // str 8
403
+ value = src[position++];
404
+ if (srcStringEnd >= position) {
405
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
406
+ }
407
+ return readString8(value)
408
+ case 0xda:
409
+ // str 16
410
+ value = dataView.getUint16(position);
411
+ position += 2;
412
+ if (srcStringEnd >= position) {
413
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
414
+ }
415
+ return readString16(value)
416
+ case 0xdb:
417
+ // str 32
418
+ value = dataView.getUint32(position);
419
+ position += 4;
420
+ if (srcStringEnd >= position) {
421
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
422
+ }
423
+ return readString32(value)
424
+ case 0xdc:
425
+ // array 16
426
+ value = dataView.getUint16(position);
427
+ position += 2;
428
+ return readArray(value)
429
+ case 0xdd:
430
+ // array 32
431
+ value = dataView.getUint32(position);
432
+ position += 4;
433
+ return readArray(value)
434
+ case 0xde:
435
+ // map 16
436
+ value = dataView.getUint16(position);
437
+ position += 2;
438
+ return readMap(value)
439
+ case 0xdf:
440
+ // map 32
441
+ value = dataView.getUint32(position);
442
+ position += 4;
443
+ return readMap(value)
444
+ default: // negative int
445
+ if (token >= 0xe0)
446
+ return token - 0x100
447
+ if (token === undefined) {
448
+ let error = new Error('Unexpected end of MessagePack data');
449
+ error.incomplete = true;
450
+ throw error
451
+ }
452
+ throw new Error('Unknown MessagePack token ' + token)
453
+
454
+ }
455
+ }
456
+ }
457
+ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
458
+ function createStructureReader(structure, firstId) {
459
+ function readObject() {
460
+ // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
461
+ if (readObject.count++ > inlineObjectReadThreshold) {
462
+ let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
463
+ if (structure.highByte === 0)
464
+ structure.read = createSecondByteReader(firstId, structure.read);
465
+ return readObject() // second byte is already read, if there is one so immediately read object
466
+ }
467
+ let object = {};
468
+ for (let i = 0, l = structure.length; i < l; i++) {
469
+ let key = structure[i];
470
+ object[key] = read();
471
+ }
472
+ return object
473
+ }
474
+ readObject.count = 0;
475
+ if (structure.highByte === 0) {
476
+ return createSecondByteReader(firstId, readObject)
477
+ }
478
+ return readObject
479
+ }
480
+
481
+ const createSecondByteReader = (firstId, read0) => {
482
+ return function() {
483
+ let highByte = src[position++];
484
+ if (highByte === 0)
485
+ return read0()
486
+ let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
487
+ let structure = currentStructures[id] || loadStructures()[id];
488
+ if (!structure) {
489
+ throw new Error('Record id is not defined for ' + id)
490
+ }
491
+ if (!structure.read)
492
+ structure.read = createStructureReader(structure, firstId);
493
+ return structure.read()
494
+ }
495
+ };
496
+
497
+ function loadStructures() {
498
+ let loadedStructures = saveState(() => {
499
+ // save the state in case getStructures modifies our buffer
500
+ src = null;
501
+ return currentUnpackr.getStructures()
502
+ });
503
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
504
+ }
505
+
506
+ var readFixedString = readStringJS;
507
+ var readString8 = readStringJS;
508
+ var readString16 = readStringJS;
509
+ var readString32 = readStringJS;
510
+ exports.isNativeAccelerationEnabled = false;
511
+
512
+ function setExtractor(extractStrings) {
513
+ exports.isNativeAccelerationEnabled = true;
514
+ readFixedString = readString(1);
515
+ readString8 = readString(2);
516
+ readString16 = readString(3);
517
+ readString32 = readString(5);
518
+ function readString(headerLength) {
519
+ return function readString(length) {
520
+ let string = strings[stringPosition++];
521
+ if (string == null) {
522
+ if (bundledStrings)
523
+ return readStringJS(length)
524
+ let extraction = extractStrings(position - headerLength, srcEnd, src);
525
+ if (typeof extraction == 'string') {
526
+ string = extraction;
527
+ strings = EMPTY_ARRAY;
528
+ } else {
529
+ strings = extraction;
530
+ stringPosition = 1;
531
+ 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
532
+ string = strings[0];
533
+ if (string === undefined)
534
+ throw new Error('Unexpected end of buffer')
535
+ }
536
+ }
537
+ let srcStringLength = string.length;
538
+ if (srcStringLength <= length) {
539
+ position += length;
540
+ return string
541
+ }
542
+ srcString = string;
543
+ srcStringStart = position;
544
+ srcStringEnd = position + srcStringLength;
545
+ position += length;
546
+ return string.slice(0, length) // we know we just want the beginning
547
+ }
548
+ }
549
+ }
550
+ function readStringJS(length) {
551
+ let result;
552
+ if (length < 16) {
553
+ if (result = shortStringInJS(length))
554
+ return result
555
+ }
556
+ if (length > 64 && decoder)
557
+ return decoder.decode(src.subarray(position, position += length))
558
+ const end = position + length;
559
+ const units = [];
560
+ result = '';
561
+ while (position < end) {
562
+ const byte1 = src[position++];
563
+ if ((byte1 & 0x80) === 0) {
564
+ // 1 byte
565
+ units.push(byte1);
566
+ } else if ((byte1 & 0xe0) === 0xc0) {
567
+ // 2 bytes
568
+ const byte2 = src[position++] & 0x3f;
569
+ units.push(((byte1 & 0x1f) << 6) | byte2);
570
+ } else if ((byte1 & 0xf0) === 0xe0) {
571
+ // 3 bytes
572
+ const byte2 = src[position++] & 0x3f;
573
+ const byte3 = src[position++] & 0x3f;
574
+ units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
575
+ } else if ((byte1 & 0xf8) === 0xf0) {
576
+ // 4 bytes
577
+ const byte2 = src[position++] & 0x3f;
578
+ const byte3 = src[position++] & 0x3f;
579
+ const byte4 = src[position++] & 0x3f;
580
+ let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
581
+ if (unit > 0xffff) {
582
+ unit -= 0x10000;
583
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
584
+ unit = 0xdc00 | (unit & 0x3ff);
585
+ }
586
+ units.push(unit);
587
+ } else {
588
+ units.push(byte1);
589
+ }
590
+
591
+ if (units.length >= 0x1000) {
592
+ result += fromCharCode.apply(String, units);
593
+ units.length = 0;
594
+ }
595
+ }
596
+
597
+ if (units.length > 0) {
598
+ result += fromCharCode.apply(String, units);
599
+ }
600
+
601
+ return result
602
+ }
603
+
604
+ function readArray(length) {
605
+ let array = new Array(length);
606
+ for (let i = 0; i < length; i++) {
607
+ array[i] = read();
608
+ }
609
+ return array
610
+ }
611
+
612
+ function readMap(length) {
613
+ if (currentUnpackr.mapsAsObjects) {
614
+ let object = {};
615
+ for (let i = 0; i < length; i++) {
616
+ object[readKey()] = read();
617
+ }
618
+ return object
619
+ } else {
620
+ let map = new Map();
621
+ for (let i = 0; i < length; i++) {
622
+ map.set(read(), read());
623
+ }
624
+ return map
625
+ }
626
+ }
627
+
628
+ var fromCharCode = String.fromCharCode;
629
+ function longStringInJS(length) {
630
+ let start = position;
631
+ let bytes = new Array(length);
632
+ for (let i = 0; i < length; i++) {
633
+ const byte = src[position++];
634
+ if ((byte & 0x80) > 0) {
635
+ position = start;
636
+ return
637
+ }
638
+ bytes[i] = byte;
639
+ }
640
+ return fromCharCode.apply(String, bytes)
641
+ }
642
+ function shortStringInJS(length) {
643
+ if (length < 4) {
644
+ if (length < 2) {
645
+ if (length === 0)
646
+ return ''
647
+ else {
648
+ let a = src[position++];
649
+ if ((a & 0x80) > 1) {
650
+ position -= 1;
651
+ return
652
+ }
653
+ return fromCharCode(a)
654
+ }
655
+ } else {
656
+ let a = src[position++];
657
+ let b = src[position++];
658
+ if ((a & 0x80) > 0 || (b & 0x80) > 0) {
659
+ position -= 2;
660
+ return
661
+ }
662
+ if (length < 3)
663
+ return fromCharCode(a, b)
664
+ let c = src[position++];
665
+ if ((c & 0x80) > 0) {
666
+ position -= 3;
667
+ return
668
+ }
669
+ return fromCharCode(a, b, c)
670
+ }
671
+ } else {
672
+ let a = src[position++];
673
+ let b = src[position++];
674
+ let c = src[position++];
675
+ let d = src[position++];
676
+ if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
677
+ position -= 4;
678
+ return
679
+ }
680
+ if (length < 6) {
681
+ if (length === 4)
682
+ return fromCharCode(a, b, c, d)
683
+ else {
684
+ let e = src[position++];
685
+ if ((e & 0x80) > 0) {
686
+ position -= 5;
687
+ return
688
+ }
689
+ return fromCharCode(a, b, c, d, e)
690
+ }
691
+ } else if (length < 8) {
692
+ let e = src[position++];
693
+ let f = src[position++];
694
+ if ((e & 0x80) > 0 || (f & 0x80) > 0) {
695
+ position -= 6;
696
+ return
697
+ }
698
+ if (length < 7)
699
+ return fromCharCode(a, b, c, d, e, f)
700
+ let g = src[position++];
701
+ if ((g & 0x80) > 0) {
702
+ position -= 7;
703
+ return
704
+ }
705
+ return fromCharCode(a, b, c, d, e, f, g)
706
+ } else {
707
+ let e = src[position++];
708
+ let f = src[position++];
709
+ let g = src[position++];
710
+ let h = src[position++];
711
+ if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
712
+ position -= 8;
713
+ return
714
+ }
715
+ if (length < 10) {
716
+ if (length === 8)
717
+ return fromCharCode(a, b, c, d, e, f, g, h)
718
+ else {
719
+ let i = src[position++];
720
+ if ((i & 0x80) > 0) {
721
+ position -= 9;
722
+ return
723
+ }
724
+ return fromCharCode(a, b, c, d, e, f, g, h, i)
725
+ }
726
+ } else if (length < 12) {
727
+ let i = src[position++];
728
+ let j = src[position++];
729
+ if ((i & 0x80) > 0 || (j & 0x80) > 0) {
730
+ position -= 10;
731
+ return
732
+ }
733
+ if (length < 11)
734
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j)
735
+ let k = src[position++];
736
+ if ((k & 0x80) > 0) {
737
+ position -= 11;
738
+ return
739
+ }
740
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
741
+ } else {
742
+ let i = src[position++];
743
+ let j = src[position++];
744
+ let k = src[position++];
745
+ let l = src[position++];
746
+ if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
747
+ position -= 12;
748
+ return
749
+ }
750
+ if (length < 14) {
751
+ if (length === 12)
752
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
753
+ else {
754
+ let m = src[position++];
755
+ if ((m & 0x80) > 0) {
756
+ position -= 13;
757
+ return
758
+ }
759
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
760
+ }
761
+ } else {
762
+ let m = src[position++];
763
+ let n = src[position++];
764
+ if ((m & 0x80) > 0 || (n & 0x80) > 0) {
765
+ position -= 14;
766
+ return
767
+ }
768
+ if (length < 15)
769
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
770
+ let o = src[position++];
771
+ if ((o & 0x80) > 0) {
772
+ position -= 15;
773
+ return
774
+ }
775
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
776
+ }
777
+ }
778
+ }
779
+ }
780
+ }
781
+
782
+ function readOnlyJSString() {
783
+ let token = src[position++];
784
+ let length;
785
+ if (token < 0xc0) {
786
+ // fixstr
787
+ length = token - 0xa0;
788
+ } else {
789
+ switch(token) {
790
+ case 0xd9:
791
+ // str 8
792
+ length = src[position++];
793
+ break
794
+ case 0xda:
795
+ // str 16
796
+ length = dataView.getUint16(position);
797
+ position += 2;
798
+ break
799
+ case 0xdb:
800
+ // str 32
801
+ length = dataView.getUint32(position);
802
+ position += 4;
803
+ break
804
+ default:
805
+ throw new Error('Expected string')
806
+ }
807
+ }
808
+ return readStringJS(length)
809
+ }
810
+
811
+
812
+ function readBin(length) {
813
+ return currentUnpackr.copyBuffers ?
814
+ // specifically use the copying slice (not the node one)
815
+ Uint8Array.prototype.slice.call(src, position, position += length) :
816
+ src.subarray(position, position += length)
817
+ }
818
+ function readExt(length) {
819
+ let type = src[position++];
820
+ if (currentExtensions[type]) {
821
+ return currentExtensions[type](src.subarray(position, position += length))
822
+ }
823
+ else
824
+ throw new Error('Unknown extension type ' + type)
825
+ }
826
+
827
+ var keyCache = new Array(4096);
828
+ function readKey() {
829
+ let length = src[position++];
830
+ if (length >= 0xa0 && length < 0xc0) {
831
+ // fixstr, potentially use key cache
832
+ length = length - 0xa0;
833
+ if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
834
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
835
+ else if (!(srcStringEnd == 0 && srcEnd < 180))
836
+ return readFixedString(length)
837
+ } else { // not cacheable, go back and do a standard read
838
+ position--;
839
+ return read()
840
+ }
841
+ let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
842
+ let entry = keyCache[key];
843
+ let checkPosition = position;
844
+ let end = position + length - 3;
845
+ let chunk;
846
+ let i = 0;
847
+ if (entry && entry.bytes == length) {
848
+ while (checkPosition < end) {
849
+ chunk = dataView.getUint32(checkPosition);
850
+ if (chunk != entry[i++]) {
851
+ checkPosition = 0x70000000;
852
+ break
853
+ }
854
+ checkPosition += 4;
855
+ }
856
+ end += 3;
857
+ while (checkPosition < end) {
858
+ chunk = src[checkPosition++];
859
+ if (chunk != entry[i++]) {
860
+ checkPosition = 0x70000000;
861
+ break
862
+ }
863
+ }
864
+ if (checkPosition === end) {
865
+ position = checkPosition;
866
+ return entry.string
867
+ }
868
+ end -= 3;
869
+ checkPosition = position;
870
+ }
871
+ entry = [];
872
+ keyCache[key] = entry;
873
+ entry.bytes = length;
874
+ while (checkPosition < end) {
875
+ chunk = dataView.getUint32(checkPosition);
876
+ entry.push(chunk);
877
+ checkPosition += 4;
878
+ }
879
+ end += 3;
880
+ while (checkPosition < end) {
881
+ chunk = src[checkPosition++];
882
+ entry.push(chunk);
883
+ }
884
+ // for small blocks, avoiding the overhead of the extract call is helpful
885
+ let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
886
+ if (string != null)
887
+ return entry.string = string
888
+ return entry.string = readFixedString(length)
889
+ }
890
+
891
+ // the registration of the record definition extension (as "r")
892
+ const recordDefinition = (id, highByte) => {
893
+ var structure = read();
894
+ let firstByte = id;
895
+ if (highByte !== undefined) {
896
+ id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
897
+ structure.highByte = highByte;
898
+ }
899
+ let existingStructure = currentStructures[id];
900
+ if (existingStructure && existingStructure.isShared) {
901
+ (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
902
+ }
903
+ currentStructures[id] = structure;
904
+ structure.read = createStructureReader(structure, firstByte);
905
+ return structure.read()
906
+ };
907
+ currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
908
+ currentExtensions[0].noBuffer = true;
909
+
910
+ currentExtensions[0x65] = () => {
911
+ let data = read();
912
+ return (globalThis[data[0]] || Error)(data[1])
913
+ };
914
+
915
+ currentExtensions[0x69] = (data) => {
916
+ // id extension (for structured clones)
917
+ let id = dataView.getUint32(position - 4);
918
+ if (!referenceMap)
919
+ referenceMap = new Map();
920
+ let token = src[position];
921
+ let target;
922
+ // TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
923
+ // ahead past references to record structure definitions
924
+ if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
925
+ target = [];
926
+ else
927
+ target = {};
928
+
929
+ let refEntry = { target }; // a placeholder object
930
+ referenceMap.set(id, refEntry);
931
+ let targetProperties = read(); // read the next value as the target object to id
932
+ if (refEntry.used) // there is a cycle, so we have to assign properties to original target
933
+ return Object.assign(target, targetProperties)
934
+ refEntry.target = targetProperties; // the placeholder wasn't used, replace with the deserialized one
935
+ return targetProperties // no cycle, can just use the returned read object
936
+ };
937
+
938
+ currentExtensions[0x70] = (data) => {
939
+ // pointer extension (for structured clones)
940
+ let id = dataView.getUint32(position - 4);
941
+ let refEntry = referenceMap.get(id);
942
+ refEntry.used = true;
943
+ return refEntry.target
944
+ };
945
+
946
+ currentExtensions[0x73] = () => new Set(read());
947
+
948
+ const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
949
+
950
+ currentExtensions[0x74] = (data) => {
951
+ let typeCode = data[0];
952
+ let typedArrayName = typedArrays[typeCode];
953
+ if (!typedArrayName)
954
+ throw new Error('Could not find typed array for code ' + typeCode)
955
+ // we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
956
+ return new globalThis[typedArrayName](Uint8Array.prototype.slice.call(data, 1).buffer)
957
+ };
958
+ currentExtensions[0x78] = () => {
959
+ let data = read();
960
+ return new RegExp(data[0], data[1])
961
+ };
962
+ const TEMP_BUNDLE = [];
963
+ currentExtensions[0x62] = (data) => {
964
+ let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
965
+ let dataPosition = position;
966
+ position += dataSize - data.length;
967
+ bundledStrings = TEMP_BUNDLE;
968
+ bundledStrings = [readOnlyJSString(), readOnlyJSString()];
969
+ bundledStrings.position0 = 0;
970
+ bundledStrings.position1 = 0;
971
+ bundledStrings.postBundlePosition = position;
972
+ position = dataPosition;
973
+ return read()
974
+ };
975
+
976
+ currentExtensions[0xff] = (data) => {
977
+ // 32-bit date extension
978
+ if (data.length == 4)
979
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
980
+ else if (data.length == 8)
981
+ return new Date(
982
+ ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
983
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
984
+ else if (data.length == 12)// TODO: Implement support for negative
985
+ return new Date(
986
+ ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
987
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
988
+ else
989
+ return new Date('invalid')
990
+ }; // notepack defines extension 0 to mean undefined, so use that as the default here
991
+ // registration of bulk record definition?
992
+ // currentExtensions[0x52] = () =>
993
+
994
+ function saveState(callback) {
995
+ let savedSrcEnd = srcEnd;
996
+ let savedPosition = position;
997
+ let savedStringPosition = stringPosition;
998
+ let savedSrcStringStart = srcStringStart;
999
+ let savedSrcStringEnd = srcStringEnd;
1000
+ let savedSrcString = srcString;
1001
+ let savedStrings = strings;
1002
+ let savedReferenceMap = referenceMap;
1003
+ let savedBundledStrings = bundledStrings;
1004
+
1005
+ // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
1006
+ let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
1007
+ let savedStructures = currentStructures;
1008
+ let savedStructuresContents = currentStructures.slice(0, currentStructures.length);
1009
+ let savedPackr = currentUnpackr;
1010
+ let savedSequentialMode = sequentialMode;
1011
+ let value = callback();
1012
+ srcEnd = savedSrcEnd;
1013
+ position = savedPosition;
1014
+ stringPosition = savedStringPosition;
1015
+ srcStringStart = savedSrcStringStart;
1016
+ srcStringEnd = savedSrcStringEnd;
1017
+ srcString = savedSrcString;
1018
+ strings = savedStrings;
1019
+ referenceMap = savedReferenceMap;
1020
+ bundledStrings = savedBundledStrings;
1021
+ src = savedSrc;
1022
+ sequentialMode = savedSequentialMode;
1023
+ currentStructures = savedStructures;
1024
+ currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1025
+ currentUnpackr = savedPackr;
1026
+ dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1027
+ return value
1028
+ }
1029
+ function clearSource() {
1030
+ src = null;
1031
+ referenceMap = null;
1032
+ currentStructures = null;
1033
+ }
1034
+
1035
+ function addExtension(extension) {
1036
+ if (extension.unpack)
1037
+ currentExtensions[extension.type] = extension.unpack;
1038
+ else
1039
+ currentExtensions[extension.type] = extension;
1040
+ }
1041
+
1042
+ const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1043
+ for (let i = 0; i < 256; i++) {
1044
+ mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
1045
+ }
1046
+ const Decoder = Unpackr;
1047
+ var defaultUnpackr = new Unpackr({ useRecords: false });
1048
+ const unpack = defaultUnpackr.unpack;
1049
+ const unpackMultiple = defaultUnpackr.unpackMultiple;
1050
+ const decode = defaultUnpackr.unpack;
1051
+ const FLOAT32_OPTIONS = {
1052
+ NEVER: 0,
1053
+ ALWAYS: 1,
1054
+ DECIMAL_ROUND: 3,
1055
+ DECIMAL_FIT: 4
1056
+ };
1057
+ let f32Array = new Float32Array(1);
1058
+ let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1059
+ function roundFloat32(float32Number) {
1060
+ f32Array[0] = float32Number;
1061
+ let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1062
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1063
+ }
1064
+
1065
+ let textEncoder;
1066
+ try {
1067
+ textEncoder = new TextEncoder();
1068
+ } catch (error) {}
1069
+ let extensions, extensionClasses;
1070
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
1071
+ const ByteArrayAllocate = hasNodeBuffer ?
1072
+ function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1073
+ const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1074
+ const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1075
+ let target, keysTarget;
1076
+ let targetView;
1077
+ let position$1 = 0;
1078
+ let safeEnd;
1079
+ let bundledStrings$1 = null;
1080
+ const MAX_BUNDLE_SIZE = 0xf000;
1081
+ const hasNonLatin = /[\u0080-\uFFFF]/;
1082
+ const RECORD_SYMBOL = Symbol('record-id');
1083
+ class Packr extends Unpackr {
1084
+ constructor(options) {
1085
+ super(options);
1086
+ this.offset = 0;
1087
+ let start;
1088
+ let hasSharedUpdate;
1089
+ let structures;
1090
+ let referenceMap;
1091
+ let lastSharedStructuresLength = 0;
1092
+ let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1093
+ return target.utf8Write(string, position, 0xffffffff)
1094
+ } : (textEncoder && textEncoder.encodeInto) ?
1095
+ function(string, position) {
1096
+ return textEncoder.encodeInto(string, target.subarray(position)).written
1097
+ } : false;
1098
+
1099
+ let packr = this;
1100
+ if (!options)
1101
+ options = {};
1102
+ let isSequential = options && options.sequential;
1103
+ let hasSharedStructures = options.structures || options.saveStructures;
1104
+ let maxSharedStructures = options.maxSharedStructures;
1105
+ if (maxSharedStructures == null)
1106
+ maxSharedStructures = hasSharedStructures ? 32 : 0;
1107
+ if (maxSharedStructures > 8160)
1108
+ throw new Error('Maximum maxSharedStructure is 8160')
1109
+ if (options.structuredClone && options.moreTypes == undefined) {
1110
+ options.moreTypes = true;
1111
+ }
1112
+ let maxOwnStructures = options.maxOwnStructures;
1113
+ if (maxOwnStructures == null)
1114
+ maxOwnStructures = hasSharedStructures ? 32 : 64;
1115
+ if (!this.structures && options.useRecords != false)
1116
+ this.structures = [];
1117
+ // two byte record ids for shared structures
1118
+ let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
1119
+ let sharedLimitId = maxSharedStructures + 0x40;
1120
+ let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1121
+ if (maxStructureId > 8256) {
1122
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1123
+ }
1124
+ let recordIdsToRemove = [];
1125
+ let transitionsCount = 0;
1126
+ let serializationsSinceTransitionRebuild = 0;
1127
+
1128
+ this.pack = this.encode = function(value, encodeOptions) {
1129
+ if (!target) {
1130
+ target = new ByteArrayAllocate(8192);
1131
+ targetView = new DataView(target.buffer, 0, 8192);
1132
+ position$1 = 0;
1133
+ }
1134
+ safeEnd = target.length - 10;
1135
+ if (safeEnd - position$1 < 0x800) {
1136
+ // don't start too close to the end,
1137
+ target = new ByteArrayAllocate(target.length);
1138
+ targetView = new DataView(target.buffer, 0, target.length);
1139
+ safeEnd = target.length - 10;
1140
+ position$1 = 0;
1141
+ } else
1142
+ position$1 = (position$1 + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1143
+ start = position$1;
1144
+ referenceMap = packr.structuredClone ? new Map() : null;
1145
+ if (packr.bundleStrings && typeof value !== 'string') {
1146
+ bundledStrings$1 = [];
1147
+ bundledStrings$1.size = Infinity; // force a new bundle start on first string
1148
+ } else
1149
+ bundledStrings$1 = null;
1150
+ structures = packr.structures;
1151
+ if (structures) {
1152
+ if (structures.uninitialized)
1153
+ structures = packr._mergeStructures(packr.getStructures());
1154
+ let sharedLength = structures.sharedLength || 0;
1155
+ if (sharedLength > maxSharedStructures) {
1156
+ //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1157
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1158
+ }
1159
+ if (!structures.transitions) {
1160
+ // rebuild our structure transitions
1161
+ structures.transitions = Object.create(null);
1162
+ for (let i = 0; i < sharedLength; i++) {
1163
+ let keys = structures[i];
1164
+ if (!keys)
1165
+ continue
1166
+ let nextTransition, transition = structures.transitions;
1167
+ for (let j = 0, l = keys.length; j < l; j++) {
1168
+ let key = keys[j];
1169
+ nextTransition = transition[key];
1170
+ if (!nextTransition) {
1171
+ nextTransition = transition[key] = Object.create(null);
1172
+ }
1173
+ transition = nextTransition;
1174
+ }
1175
+ transition[RECORD_SYMBOL] = i + 0x40;
1176
+ }
1177
+ lastSharedStructuresLength = sharedLength;
1178
+ }
1179
+ if (!isSequential) {
1180
+ structures.nextId = sharedLength + 0x40;
1181
+ }
1182
+ }
1183
+ if (hasSharedUpdate)
1184
+ hasSharedUpdate = false;
1185
+ try {
1186
+ pack(value);
1187
+ if (bundledStrings$1) {
1188
+ writeBundles(start, pack);
1189
+ }
1190
+ packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1191
+ if (referenceMap && referenceMap.idsToInsert) {
1192
+ position$1 += referenceMap.idsToInsert.length * 6;
1193
+ if (position$1 > safeEnd)
1194
+ makeRoom(position$1);
1195
+ packr.offset = position$1;
1196
+ let serialized = insertIds(target.subarray(start, position$1), referenceMap.idsToInsert);
1197
+ referenceMap = null;
1198
+ return serialized
1199
+ }
1200
+ if (encodeOptions & REUSE_BUFFER_MODE) {
1201
+ target.start = start;
1202
+ target.end = position$1;
1203
+ return target
1204
+ }
1205
+ return target.subarray(start, position$1) // position can change if we call pack again in saveStructures, so we get the buffer now
1206
+ } finally {
1207
+ if (structures) {
1208
+ if (serializationsSinceTransitionRebuild < 10)
1209
+ serializationsSinceTransitionRebuild++;
1210
+ let sharedLength = structures.sharedLength || maxSharedStructures;
1211
+ if (structures.length > sharedLength)
1212
+ structures.length = sharedLength;
1213
+ if (transitionsCount > 10000) {
1214
+ // force a rebuild occasionally after a lot of transitions so it can get cleaned up
1215
+ structures.transitions = null;
1216
+ serializationsSinceTransitionRebuild = 0;
1217
+ transitionsCount = 0;
1218
+ if (recordIdsToRemove.length > 0)
1219
+ recordIdsToRemove = [];
1220
+ } else if (recordIdsToRemove.length > 0 && !isSequential) {
1221
+ for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
1222
+ recordIdsToRemove[i][RECORD_SYMBOL] = 0;
1223
+ }
1224
+ recordIdsToRemove = [];
1225
+ }
1226
+ if (hasSharedUpdate && packr.saveStructures) {
1227
+ // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1228
+ let returnBuffer = target.subarray(start, position$1);
1229
+ if (packr.saveStructures(structures, lastSharedStructuresLength) === false) {
1230
+ // get updated structures and try again if the update failed
1231
+ packr._mergeStructures(packr.getStructures());
1232
+ return packr.pack(value)
1233
+ }
1234
+ lastSharedStructuresLength = sharedLength;
1235
+ return returnBuffer
1236
+ }
1237
+ }
1238
+ if (encodeOptions & RESET_BUFFER_MODE)
1239
+ position$1 = start;
1240
+ }
1241
+ };
1242
+ const pack = (value) => {
1243
+ if (position$1 > safeEnd)
1244
+ target = makeRoom(position$1);
1245
+
1246
+ var type = typeof value;
1247
+ var length;
1248
+ if (type === 'string') {
1249
+ let strLength = value.length;
1250
+ if (bundledStrings$1 && strLength >= 4 && strLength < 0x1000) {
1251
+ if ((bundledStrings$1.size += strLength) > MAX_BUNDLE_SIZE) {
1252
+ let extStart;
1253
+ let maxBytes = (bundledStrings$1[0] ? bundledStrings$1[0].length * 3 + bundledStrings$1[1].length : 0) + 10;
1254
+ if (position$1 + maxBytes > safeEnd)
1255
+ target = makeRoom(position$1 + maxBytes);
1256
+ if (bundledStrings$1.position) { // here we use the 0x62 extension to write the last bundle and reserve sapce for the reference pointer to the next/current bundle
1257
+ target[position$1] = 0xc8; // ext 16
1258
+ position$1 += 3; // reserve for the writing bundle size
1259
+ target[position$1++] = 0x62; // 'b'
1260
+ extStart = position$1 - start;
1261
+ position$1 += 4; // reserve for writing bundle reference
1262
+ writeBundles(start, pack); // write the last bundles
1263
+ targetView.setUint16(extStart + start - 3, position$1 - start - extStart);
1264
+ } else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
1265
+ target[position$1++] = 0xd6; // fixext 4
1266
+ target[position$1++] = 0x62; // 'b'
1267
+ extStart = position$1 - start;
1268
+ position$1 += 4; // reserve for writing bundle reference
1269
+ }
1270
+ bundledStrings$1 = ['', '']; // create new ones
1271
+ bundledStrings$1.size = 0;
1272
+ bundledStrings$1.position = extStart;
1273
+ }
1274
+ let twoByte = hasNonLatin.test(value);
1275
+ bundledStrings$1[twoByte ? 0 : 1] += value;
1276
+ target[position$1++] = 0xc1;
1277
+ pack(twoByte ? -strLength : strLength);
1278
+ return
1279
+ }
1280
+ let headerSize;
1281
+ // first we estimate the header size, so we can write to the correct location
1282
+ if (strLength < 0x20) {
1283
+ headerSize = 1;
1284
+ } else if (strLength < 0x100) {
1285
+ headerSize = 2;
1286
+ } else if (strLength < 0x10000) {
1287
+ headerSize = 3;
1288
+ } else {
1289
+ headerSize = 5;
1290
+ }
1291
+ let maxBytes = strLength * 3;
1292
+ if (position$1 + maxBytes > safeEnd)
1293
+ target = makeRoom(position$1 + maxBytes);
1294
+
1295
+ if (strLength < 0x40 || !encodeUtf8) {
1296
+ let i, c1, c2, strPosition = position$1 + headerSize;
1297
+ for (i = 0; i < strLength; i++) {
1298
+ c1 = value.charCodeAt(i);
1299
+ if (c1 < 0x80) {
1300
+ target[strPosition++] = c1;
1301
+ } else if (c1 < 0x800) {
1302
+ target[strPosition++] = c1 >> 6 | 0xc0;
1303
+ target[strPosition++] = c1 & 0x3f | 0x80;
1304
+ } else if (
1305
+ (c1 & 0xfc00) === 0xd800 &&
1306
+ ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
1307
+ ) {
1308
+ c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
1309
+ i++;
1310
+ target[strPosition++] = c1 >> 18 | 0xf0;
1311
+ target[strPosition++] = c1 >> 12 & 0x3f | 0x80;
1312
+ target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
1313
+ target[strPosition++] = c1 & 0x3f | 0x80;
1314
+ } else {
1315
+ target[strPosition++] = c1 >> 12 | 0xe0;
1316
+ target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
1317
+ target[strPosition++] = c1 & 0x3f | 0x80;
1318
+ }
1319
+ }
1320
+ length = strPosition - position$1 - headerSize;
1321
+ } else {
1322
+ length = encodeUtf8(value, position$1 + headerSize);
1323
+ }
1324
+
1325
+ if (length < 0x20) {
1326
+ target[position$1++] = 0xa0 | length;
1327
+ } else if (length < 0x100) {
1328
+ if (headerSize < 2) {
1329
+ target.copyWithin(position$1 + 2, position$1 + 1, position$1 + 1 + length);
1330
+ }
1331
+ target[position$1++] = 0xd9;
1332
+ target[position$1++] = length;
1333
+ } else if (length < 0x10000) {
1334
+ if (headerSize < 3) {
1335
+ target.copyWithin(position$1 + 3, position$1 + 2, position$1 + 2 + length);
1336
+ }
1337
+ target[position$1++] = 0xda;
1338
+ target[position$1++] = length >> 8;
1339
+ target[position$1++] = length & 0xff;
1340
+ } else {
1341
+ if (headerSize < 5) {
1342
+ target.copyWithin(position$1 + 5, position$1 + 3, position$1 + 3 + length);
1343
+ }
1344
+ target[position$1++] = 0xdb;
1345
+ targetView.setUint32(position$1, length);
1346
+ position$1 += 4;
1347
+ }
1348
+ position$1 += length;
1349
+ } else if (type === 'number') {
1350
+ if (value >>> 0 === value) {// positive integer, 32-bit or less
1351
+ // positive uint
1352
+ if (value < 0x40 || (value < 0x80 && this.useRecords === false)) {
1353
+ target[position$1++] = value;
1354
+ } else if (value < 0x100) {
1355
+ target[position$1++] = 0xcc;
1356
+ target[position$1++] = value;
1357
+ } else if (value < 0x10000) {
1358
+ target[position$1++] = 0xcd;
1359
+ target[position$1++] = value >> 8;
1360
+ target[position$1++] = value & 0xff;
1361
+ } else {
1362
+ target[position$1++] = 0xce;
1363
+ targetView.setUint32(position$1, value);
1364
+ position$1 += 4;
1365
+ }
1366
+ } else if (value >> 0 === value) { // negative integer
1367
+ if (value >= -0x20) {
1368
+ target[position$1++] = 0x100 + value;
1369
+ } else if (value >= -0x80) {
1370
+ target[position$1++] = 0xd0;
1371
+ target[position$1++] = value + 0x100;
1372
+ } else if (value >= -0x8000) {
1373
+ target[position$1++] = 0xd1;
1374
+ targetView.setInt16(position$1, value);
1375
+ position$1 += 2;
1376
+ } else {
1377
+ target[position$1++] = 0xd2;
1378
+ targetView.setInt32(position$1, value);
1379
+ position$1 += 4;
1380
+ }
1381
+ } else {
1382
+ let useFloat32;
1383
+ if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
1384
+ target[position$1++] = 0xca;
1385
+ targetView.setFloat32(position$1, value);
1386
+ let xShifted;
1387
+ if (useFloat32 < 4 ||
1388
+ // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1389
+ ((xShifted = value * mult10[((target[position$1] & 0x7f) << 1) | (target[position$1 + 1] >> 7)]) >> 0) === xShifted) {
1390
+ position$1 += 4;
1391
+ return
1392
+ } else
1393
+ position$1--; // move back into position for writing a double
1394
+ }
1395
+ target[position$1++] = 0xcb;
1396
+ targetView.setFloat64(position$1, value);
1397
+ position$1 += 8;
1398
+ }
1399
+ } else if (type === 'object') {
1400
+ if (!value)
1401
+ target[position$1++] = 0xc0;
1402
+ else {
1403
+ if (referenceMap) {
1404
+ let referee = referenceMap.get(value);
1405
+ if (referee) {
1406
+ if (!referee.id) {
1407
+ let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
1408
+ referee.id = idsToInsert.push(referee);
1409
+ }
1410
+ target[position$1++] = 0xd6; // fixext 4
1411
+ target[position$1++] = 0x70; // "p" for pointer
1412
+ targetView.setUint32(position$1, referee.id);
1413
+ position$1 += 4;
1414
+ return
1415
+ } else
1416
+ referenceMap.set(value, { offset: position$1 - start });
1417
+ }
1418
+ let constructor = value.constructor;
1419
+ if (constructor === Object) {
1420
+ writeObject(value, true);
1421
+ } else if (constructor === Array) {
1422
+ length = value.length;
1423
+ if (length < 0x10) {
1424
+ target[position$1++] = 0x90 | length;
1425
+ } else if (length < 0x10000) {
1426
+ target[position$1++] = 0xdc;
1427
+ target[position$1++] = length >> 8;
1428
+ target[position$1++] = length & 0xff;
1429
+ } else {
1430
+ target[position$1++] = 0xdd;
1431
+ targetView.setUint32(position$1, length);
1432
+ position$1 += 4;
1433
+ }
1434
+ for (let i = 0; i < length; i++) {
1435
+ pack(value[i]);
1436
+ }
1437
+ } else if (constructor === Map) {
1438
+ length = value.size;
1439
+ if (length < 0x10) {
1440
+ target[position$1++] = 0x80 | length;
1441
+ } else if (length < 0x10000) {
1442
+ target[position$1++] = 0xde;
1443
+ target[position$1++] = length >> 8;
1444
+ target[position$1++] = length & 0xff;
1445
+ } else {
1446
+ target[position$1++] = 0xdf;
1447
+ targetView.setUint32(position$1, length);
1448
+ position$1 += 4;
1449
+ }
1450
+ for (let [ key, entryValue ] of value) {
1451
+ pack(key);
1452
+ pack(entryValue);
1453
+ }
1454
+ } else {
1455
+ for (let i = 0, l = extensions.length; i < l; i++) {
1456
+ let extensionClass = extensionClasses[i];
1457
+ if (value instanceof extensionClass) {
1458
+ let extension = extensions[i];
1459
+ if (extension.write) {
1460
+ if (extension.type) {
1461
+ target[position$1++] = 0xd4; // one byte "tag" extension
1462
+ target[position$1++] = extension.type;
1463
+ target[position$1++] = 0;
1464
+ }
1465
+ pack(extension.write.call(this, value));
1466
+ return
1467
+ }
1468
+ let currentTarget = target;
1469
+ let currentTargetView = targetView;
1470
+ let currentPosition = position$1;
1471
+ target = null;
1472
+ let result;
1473
+ try {
1474
+ result = extension.pack.call(this, value, (size) => {
1475
+ // restore target and use it
1476
+ target = currentTarget;
1477
+ currentTarget = null;
1478
+ position$1 += size;
1479
+ if (position$1 > safeEnd)
1480
+ makeRoom(position$1);
1481
+ return {
1482
+ target, targetView, position: position$1 - size
1483
+ }
1484
+ }, pack);
1485
+ } finally {
1486
+ // restore current target information (unless already restored)
1487
+ if (currentTarget) {
1488
+ target = currentTarget;
1489
+ targetView = currentTargetView;
1490
+ position$1 = currentPosition;
1491
+ safeEnd = target.length - 10;
1492
+ }
1493
+ }
1494
+ if (result) {
1495
+ if (result.length + position$1 > safeEnd)
1496
+ makeRoom(result.length + position$1);
1497
+ position$1 = writeExtensionData(result, target, position$1, extension.type);
1498
+ }
1499
+ return
1500
+ }
1501
+ }
1502
+ // no extension found, write as object
1503
+ writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
1504
+ }
1505
+ }
1506
+ } else if (type === 'boolean') {
1507
+ target[position$1++] = value ? 0xc3 : 0xc2;
1508
+ } else if (type === 'bigint') {
1509
+ if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
1510
+ // use a signed int as long as it fits
1511
+ target[position$1++] = 0xd3;
1512
+ targetView.setBigInt64(position$1, value);
1513
+ } else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
1514
+ // if we can fit an unsigned int, use that
1515
+ target[position$1++] = 0xcf;
1516
+ targetView.setBigUint64(position$1, value);
1517
+ } else {
1518
+ // overflow
1519
+ if (this.largeBigIntToFloat) {
1520
+ target[position$1++] = 0xcb;
1521
+ targetView.setFloat64(position$1, Number(value));
1522
+ } else {
1523
+ throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
1524
+ }
1525
+ }
1526
+ position$1 += 8;
1527
+ } else if (type === 'undefined') {
1528
+ if (this.encodeUndefinedAsNil)
1529
+ target[position$1++] = 0xc0;
1530
+ else {
1531
+ target[position$1++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1532
+ target[position$1++] = 0;
1533
+ target[position$1++] = 0;
1534
+ }
1535
+ } else if (type === 'function') {
1536
+ pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
1537
+ } else {
1538
+ throw new Error('Unknown type: ' + type)
1539
+ }
1540
+ };
1541
+
1542
+ const writeObject = this.useRecords === false ? this.variableMapSize ? (object) => {
1543
+ // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
1544
+ let keys = Object.keys(object);
1545
+ let length = keys.length;
1546
+ if (length < 0x10) {
1547
+ target[position$1++] = 0x80 | length;
1548
+ } else if (length < 0x10000) {
1549
+ target[position$1++] = 0xde;
1550
+ target[position$1++] = length >> 8;
1551
+ target[position$1++] = length & 0xff;
1552
+ } else {
1553
+ target[position$1++] = 0xdf;
1554
+ targetView.setUint32(position$1, length);
1555
+ position$1 += 4;
1556
+ }
1557
+ let key;
1558
+ for (let i = 0; i < length; i++) {
1559
+ pack(key = keys[i]);
1560
+ pack(object[key]);
1561
+ }
1562
+ } :
1563
+ (object, safePrototype) => {
1564
+ target[position$1++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1565
+ let objectOffset = position$1 - start;
1566
+ position$1 += 2;
1567
+ let size = 0;
1568
+ for (let key in object) {
1569
+ if (safePrototype || object.hasOwnProperty(key)) {
1570
+ pack(key);
1571
+ pack(object[key]);
1572
+ size++;
1573
+ }
1574
+ }
1575
+ target[objectOffset++ + start] = size >> 8;
1576
+ target[objectOffset + start] = size & 0xff;
1577
+ } :
1578
+ (options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
1579
+ (object, safePrototype) => {
1580
+ let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1581
+ let objectOffset = position$1++ - start;
1582
+ let wroteKeys;
1583
+ for (let key in object) {
1584
+ if (safePrototype || object.hasOwnProperty(key)) {
1585
+ nextTransition = transition[key];
1586
+ if (nextTransition)
1587
+ transition = nextTransition;
1588
+ else {
1589
+ // record doesn't exist, create full new record and insert it
1590
+ let keys = Object.keys(object);
1591
+ let lastTransition = transition;
1592
+ transition = structures.transitions;
1593
+ let newTransitions = 0;
1594
+ for (let i = 0, l = keys.length; i < l; i++) {
1595
+ let key = keys[i];
1596
+ nextTransition = transition[key];
1597
+ if (!nextTransition) {
1598
+ nextTransition = transition[key] = Object.create(null);
1599
+ newTransitions++;
1600
+ }
1601
+ transition = nextTransition;
1602
+ }
1603
+ if (objectOffset + start + 1 == position$1) {
1604
+ // first key, so we don't need to insert, we can just write record directly
1605
+ position$1--;
1606
+ newRecord(transition, keys, newTransitions);
1607
+ } else // otherwise we need to insert the record, moving existing data after the record
1608
+ insertNewRecord(transition, keys, objectOffset, newTransitions);
1609
+ wroteKeys = true;
1610
+ transition = lastTransition[key];
1611
+ }
1612
+ pack(object[key]);
1613
+ }
1614
+ }
1615
+ if (!wroteKeys) {
1616
+ let recordId = transition[RECORD_SYMBOL];
1617
+ if (recordId)
1618
+ target[objectOffset + start] = recordId;
1619
+ else
1620
+ insertNewRecord(transition, Object.keys(object), objectOffset, 0);
1621
+ }
1622
+ } :
1623
+ (object, safePrototype) => {
1624
+ let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1625
+ let newTransitions = 0;
1626
+ for (let key in object) if (safePrototype || object.hasOwnProperty(key)) {
1627
+ nextTransition = transition[key];
1628
+ if (!nextTransition) {
1629
+ nextTransition = transition[key] = Object.create(null);
1630
+ newTransitions++;
1631
+ }
1632
+ transition = nextTransition;
1633
+ }
1634
+ let recordId = transition[RECORD_SYMBOL];
1635
+ if (recordId) {
1636
+ if (recordId >= 0x60 && useTwoByteRecords) {
1637
+ target[position$1++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1638
+ target[position$1++] = recordId >> 5;
1639
+ } else
1640
+ target[position$1++] = recordId;
1641
+ } else {
1642
+ newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
1643
+ }
1644
+ // now write the values
1645
+ for (let key in object)
1646
+ if (safePrototype || object.hasOwnProperty(key))
1647
+ pack(object[key]);
1648
+ };
1649
+ const makeRoom = (end) => {
1650
+ let newSize;
1651
+ if (end > 0x1000000) {
1652
+ // special handling for really large buffers
1653
+ if ((end - start) > MAX_BUFFER_SIZE)
1654
+ throw new Error('Packed buffer would be larger than maximum buffer size')
1655
+ newSize = Math.min(MAX_BUFFER_SIZE,
1656
+ Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1657
+ } else // faster handling for smaller buffers
1658
+ newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
1659
+ let newBuffer = new ByteArrayAllocate(newSize);
1660
+ targetView = new DataView(newBuffer.buffer, 0, newSize);
1661
+ end = Math.min(end, target.length);
1662
+ if (target.copy)
1663
+ target.copy(newBuffer, 0, start, end);
1664
+ else
1665
+ newBuffer.set(target.slice(start, end));
1666
+ position$1 -= start;
1667
+ start = 0;
1668
+ safeEnd = newBuffer.length - 10;
1669
+ return target = newBuffer
1670
+ };
1671
+ const newRecord = (transition, keys, newTransitions) => {
1672
+ let recordId = structures.nextId;
1673
+ if (!recordId)
1674
+ recordId = 0x40;
1675
+ if (recordId < sharedLimitId && this.shouldShareStructure && !this.shouldShareStructure(keys)) {
1676
+ recordId = structures.nextOwnId;
1677
+ if (!(recordId < maxStructureId))
1678
+ recordId = sharedLimitId;
1679
+ structures.nextOwnId = recordId + 1;
1680
+ } else {
1681
+ if (recordId >= maxStructureId)// cycle back around
1682
+ recordId = sharedLimitId;
1683
+ structures.nextId = recordId + 1;
1684
+ }
1685
+ let highByte = keys.highByte = recordId >= 0x60 && useTwoByteRecords ? (recordId - 0x60) >> 5 : -1;
1686
+ transition[RECORD_SYMBOL] = recordId;
1687
+ transition.__keys__ = keys;
1688
+ structures[recordId - 0x40] = keys;
1689
+
1690
+ if (recordId < sharedLimitId) {
1691
+ keys.isShared = true;
1692
+ structures.sharedLength = recordId - 0x3f;
1693
+ hasSharedUpdate = true;
1694
+ if (highByte >= 0) {
1695
+ target[position$1++] = (recordId & 0x1f) + 0x60;
1696
+ target[position$1++] = highByte;
1697
+ } else {
1698
+ target[position$1++] = recordId;
1699
+ }
1700
+ } else {
1701
+ if (highByte >= 0) {
1702
+ target[position$1++] = 0xd5; // fixext 2
1703
+ target[position$1++] = 0x72; // "r" record defintion extension type
1704
+ target[position$1++] = (recordId & 0x1f) + 0x60;
1705
+ target[position$1++] = highByte;
1706
+ } else {
1707
+ target[position$1++] = 0xd4; // fixext 1
1708
+ target[position$1++] = 0x72; // "r" record defintion extension type
1709
+ target[position$1++] = recordId;
1710
+ }
1711
+
1712
+ if (newTransitions)
1713
+ transitionsCount += serializationsSinceTransitionRebuild * newTransitions;
1714
+ // record the removal of the id, we can maintain our shared structure
1715
+ if (recordIdsToRemove.length >= maxOwnStructures)
1716
+ recordIdsToRemove.shift()[RECORD_SYMBOL] = 0; // we are cycling back through, and have to remove old ones
1717
+ recordIdsToRemove.push(transition);
1718
+ pack(keys);
1719
+ }
1720
+ };
1721
+ const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
1722
+ let mainTarget = target;
1723
+ let mainPosition = position$1;
1724
+ let mainSafeEnd = safeEnd;
1725
+ let mainStart = start;
1726
+ target = keysTarget;
1727
+ position$1 = 0;
1728
+ start = 0;
1729
+ if (!target)
1730
+ keysTarget = target = new ByteArrayAllocate(8192);
1731
+ safeEnd = target.length - 10;
1732
+ newRecord(transition, keys, newTransitions);
1733
+ keysTarget = target;
1734
+ let keysPosition = position$1;
1735
+ target = mainTarget;
1736
+ position$1 = mainPosition;
1737
+ safeEnd = mainSafeEnd;
1738
+ start = mainStart;
1739
+ if (keysPosition > 1) {
1740
+ let newEnd = position$1 + keysPosition - 1;
1741
+ if (newEnd > safeEnd)
1742
+ makeRoom(newEnd);
1743
+ let insertionPosition = insertionOffset + start;
1744
+ target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position$1);
1745
+ target.set(keysTarget.slice(0, keysPosition), insertionPosition);
1746
+ position$1 = newEnd;
1747
+ } else {
1748
+ target[insertionOffset + start] = keysTarget[0];
1749
+ }
1750
+ };
1751
+ }
1752
+ useBuffer(buffer) {
1753
+ // this means we are finished using our own buffer and we can write over it safely
1754
+ target = buffer;
1755
+ targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
1756
+ position$1 = 0;
1757
+ }
1758
+ clearSharedData() {
1759
+ if (this.structures)
1760
+ this.structures = [];
1761
+ }
1762
+ }
1763
+
1764
+ extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/, C1Type ];
1765
+ extensions = [{
1766
+ pack(date, allocateForWrite, pack) {
1767
+ let seconds = date.getTime() / 1000;
1768
+ if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
1769
+ // Timestamp 32
1770
+ let { target, targetView, position} = allocateForWrite(6);
1771
+ target[position++] = 0xd6;
1772
+ target[position++] = 0xff;
1773
+ targetView.setUint32(position, seconds);
1774
+ } else if (seconds > 0 && seconds < 0x100000000) {
1775
+ // Timestamp 64
1776
+ let { target, targetView, position} = allocateForWrite(10);
1777
+ target[position++] = 0xd7;
1778
+ target[position++] = 0xff;
1779
+ targetView.setUint32(position, date.getMilliseconds() * 4000000 + ((seconds / 1000 / 0x100000000) >> 0));
1780
+ targetView.setUint32(position + 4, seconds);
1781
+ } else if (isNaN(seconds)) {
1782
+ if (this.onInvalidDate) {
1783
+ allocateForWrite(0);
1784
+ return pack(this.onInvalidDate())
1785
+ }
1786
+ // Intentionally invalid timestamp
1787
+ let { target, targetView, position} = allocateForWrite(3);
1788
+ target[position++] = 0xd4;
1789
+ target[position++] = 0xff;
1790
+ target[position++] = 0xff;
1791
+ } else {
1792
+ // Timestamp 96
1793
+ let { target, targetView, position} = allocateForWrite(15);
1794
+ target[position++] = 0xc7;
1795
+ target[position++] = 12;
1796
+ target[position++] = 0xff;
1797
+ targetView.setUint32(position, date.getMilliseconds() * 1000000);
1798
+ targetView.setBigInt64(position + 4, BigInt(Math.floor(seconds)));
1799
+ }
1800
+ }
1801
+ }, {
1802
+ pack(set, allocateForWrite, pack) {
1803
+ let array = Array.from(set);
1804
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1805
+ if (this.moreTypes) {
1806
+ target[position++] = 0xd4;
1807
+ target[position++] = 0x73; // 's' for Set
1808
+ target[position++] = 0;
1809
+ }
1810
+ pack(array);
1811
+ }
1812
+ }, {
1813
+ pack(error, allocateForWrite, pack) {
1814
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1815
+ if (this.moreTypes) {
1816
+ target[position++] = 0xd4;
1817
+ target[position++] = 0x65; // 'e' for error
1818
+ target[position++] = 0;
1819
+ }
1820
+ pack([ error.name, error.message ]);
1821
+ }
1822
+ }, {
1823
+ pack(regex, allocateForWrite, pack) {
1824
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
1825
+ if (this.moreTypes) {
1826
+ target[position++] = 0xd4;
1827
+ target[position++] = 0x78; // 'x' for regeXp
1828
+ target[position++] = 0;
1829
+ }
1830
+ pack([ regex.source, regex.flags ]);
1831
+ }
1832
+ }, {
1833
+ pack(arrayBuffer, allocateForWrite) {
1834
+ if (this.moreTypes)
1835
+ writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
1836
+ else
1837
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
1838
+ }
1839
+ }, {
1840
+ pack(typedArray, allocateForWrite) {
1841
+ let constructor = typedArray.constructor;
1842
+ if (constructor !== ByteArray && this.moreTypes)
1843
+ writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
1844
+ else
1845
+ writeBuffer(typedArray, allocateForWrite);
1846
+ }
1847
+ }, {
1848
+ pack(c1, allocateForWrite) { // specific 0xC1 object
1849
+ let { target, position} = allocateForWrite(1);
1850
+ target[position] = 0xc1;
1851
+ }
1852
+ }];
1853
+
1854
+ function writeExtBuffer(typedArray, type, allocateForWrite, encode) {
1855
+ let length = typedArray.byteLength;
1856
+ if (length + 1 < 0x100) {
1857
+ var { target, position } = allocateForWrite(4 + length);
1858
+ target[position++] = 0xc7;
1859
+ target[position++] = length + 1;
1860
+ } else if (length + 1 < 0x10000) {
1861
+ var { target, position } = allocateForWrite(5 + length);
1862
+ target[position++] = 0xc8;
1863
+ target[position++] = (length + 1) >> 8;
1864
+ target[position++] = (length + 1) & 0xff;
1865
+ } else {
1866
+ var { target, position, targetView } = allocateForWrite(7 + length);
1867
+ target[position++] = 0xc9;
1868
+ targetView.setUint32(position, length + 1); // plus one for the type byte
1869
+ position += 4;
1870
+ }
1871
+ target[position++] = 0x74; // "t" for typed array
1872
+ target[position++] = type;
1873
+ target.set(new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength), position);
1874
+ }
1875
+ function writeBuffer(buffer, allocateForWrite) {
1876
+ let length = buffer.byteLength;
1877
+ var target, position;
1878
+ if (length < 0x100) {
1879
+ var { target, position } = allocateForWrite(length + 2);
1880
+ target[position++] = 0xc4;
1881
+ target[position++] = length;
1882
+ } else if (length < 0x10000) {
1883
+ var { target, position } = allocateForWrite(length + 3);
1884
+ target[position++] = 0xc5;
1885
+ target[position++] = length >> 8;
1886
+ target[position++] = length & 0xff;
1887
+ } else {
1888
+ var { target, position, targetView } = allocateForWrite(length + 5);
1889
+ target[position++] = 0xc6;
1890
+ targetView.setUint32(position, length);
1891
+ position += 4;
1892
+ }
1893
+ target.set(buffer, position);
1894
+ }
1895
+
1896
+ function writeExtensionData(result, target, position, type) {
1897
+ let length = result.length;
1898
+ switch (length) {
1899
+ case 1:
1900
+ target[position++] = 0xd4;
1901
+ break
1902
+ case 2:
1903
+ target[position++] = 0xd5;
1904
+ break
1905
+ case 4:
1906
+ target[position++] = 0xd6;
1907
+ break
1908
+ case 8:
1909
+ target[position++] = 0xd7;
1910
+ break
1911
+ case 16:
1912
+ target[position++] = 0xd8;
1913
+ break
1914
+ default:
1915
+ if (length < 0x100) {
1916
+ target[position++] = 0xc7;
1917
+ target[position++] = length;
1918
+ } else if (length < 0x10000) {
1919
+ target[position++] = 0xc8;
1920
+ target[position++] = length >> 8;
1921
+ target[position++] = length & 0xff;
1922
+ } else {
1923
+ target[position++] = 0xc9;
1924
+ target[position++] = length >> 24;
1925
+ target[position++] = (length >> 16) & 0xff;
1926
+ target[position++] = (length >> 8) & 0xff;
1927
+ target[position++] = length & 0xff;
1928
+ }
1929
+ }
1930
+ target[position++] = type;
1931
+ target.set(result, position);
1932
+ position += length;
1933
+ return position
1934
+ }
1935
+
1936
+ function insertIds(serialized, idsToInsert) {
1937
+ // insert the ids that need to be referenced for structured clones
1938
+ let nextId;
1939
+ let distanceToMove = idsToInsert.length * 6;
1940
+ let lastEnd = serialized.length - distanceToMove;
1941
+ idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
1942
+ while (nextId = idsToInsert.pop()) {
1943
+ let offset = nextId.offset;
1944
+ let id = nextId.id;
1945
+ serialized.copyWithin(offset + distanceToMove, offset, lastEnd);
1946
+ distanceToMove -= 6;
1947
+ let position = offset + distanceToMove;
1948
+ serialized[position++] = 0xd6;
1949
+ serialized[position++] = 0x69; // 'i'
1950
+ serialized[position++] = id >> 24;
1951
+ serialized[position++] = (id >> 16) & 0xff;
1952
+ serialized[position++] = (id >> 8) & 0xff;
1953
+ serialized[position++] = id & 0xff;
1954
+ lastEnd = offset;
1955
+ }
1956
+ return serialized
1957
+ }
1958
+
1959
+ function writeBundles(start, pack) {
1960
+ if (bundledStrings$1.length > 0) {
1961
+ targetView.setUint32(bundledStrings$1.position + start, position$1 - bundledStrings$1.position - start);
1962
+ let writeStrings = bundledStrings$1;
1963
+ bundledStrings$1 = null;
1964
+ pack(writeStrings[0]);
1965
+ pack(writeStrings[1]);
1966
+ }
1967
+ }
1968
+
1969
+ function addExtension$1(extension) {
1970
+ if (extension.Class) {
1971
+ if (!extension.pack && !extension.write)
1972
+ throw new Error('Extension has no pack or write function')
1973
+ if (extension.pack && !extension.type)
1974
+ throw new Error('Extension has no type (numeric code to identify the extension)')
1975
+ extensionClasses.unshift(extension.Class);
1976
+ extensions.unshift(extension);
1977
+ }
1978
+ addExtension(extension);
1979
+ }
1980
+
1981
+ let defaultPackr = new Packr({ useRecords: false });
1982
+ const pack = defaultPackr.pack;
1983
+ const encode = defaultPackr.pack;
1984
+ const Encoder = Packr;
1985
+ const { NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = FLOAT32_OPTIONS;
1986
+ const REUSE_BUFFER_MODE = 512;
1975
1987
  const RESET_BUFFER_MODE = 1024;
1976
1988
 
1977
1989
  class PackrStream extends stream.Transform {
@@ -2112,21 +2124,23 @@ function unpackIter (bufferIterator, options = {}) {
2112
2124
  const decodeIter = unpackIter;
2113
2125
  const encodeIter = packIter;
2114
2126
 
2115
- const useRecords = false;
2116
- const mapsAsObjects = true;
2117
-
2118
- const extractor = tryRequire('msgpackr-extract');
2119
- if (extractor)
2120
- setExtractor(extractor.extractStrings);
2121
-
2122
- function tryRequire(moduleId) {
2123
- try {
2124
- let require$1 = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node.cjs', document.baseURI).href)));
2125
- return require$1(moduleId)
2126
- } catch (error) {
2127
- if (typeof window != 'undefined')
2128
- console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]);
2129
- }
2127
+ const useRecords = false;
2128
+ const mapsAsObjects = true;
2129
+
2130
+ const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
2131
+
2132
+ if (!nativeAccelerationDisabled) {
2133
+ let extractor;
2134
+ try {
2135
+ if (typeof require == 'function')
2136
+ extractor = require('msgpackr-extract');
2137
+ else
2138
+ extractor = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node.cjs', document.baseURI).href)))('msgpackr-extract');
2139
+ if (extractor)
2140
+ setExtractor(extractor.extractStrings);
2141
+ } catch (error) {
2142
+ // native module is optional
2143
+ }
2130
2144
  }
2131
2145
 
2132
2146
  exports.ALWAYS = ALWAYS;