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