@strapi/data-transfer 0.0.0-experimental.62ce06180fe9a772eaeb3d43d238b26644f39f7c → 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282

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 (395) hide show
  1. package/LICENSE +19 -4
  2. package/dist/directory/index.d.ts +2 -0
  3. package/dist/directory/index.d.ts.map +1 -0
  4. package/dist/directory/index.js +8 -0
  5. package/dist/directory/index.js.map +1 -0
  6. package/dist/directory/index.mjs +3 -0
  7. package/dist/directory/index.mjs.map +1 -0
  8. package/dist/directory/providers/destination/index.d.ts +38 -0
  9. package/dist/directory/providers/destination/index.d.ts.map +1 -0
  10. package/dist/directory/providers/destination/index.js +184 -0
  11. package/dist/directory/providers/destination/index.js.map +1 -0
  12. package/dist/directory/providers/destination/index.mjs +177 -0
  13. package/dist/directory/providers/destination/index.mjs.map +1 -0
  14. package/dist/directory/providers/destination/utils.d.ts +8 -0
  15. package/dist/directory/providers/destination/utils.d.ts.map +1 -0
  16. package/dist/directory/providers/destination/utils.js +62 -0
  17. package/dist/directory/providers/destination/utils.js.map +1 -0
  18. package/dist/directory/providers/destination/utils.mjs +56 -0
  19. package/dist/directory/providers/destination/utils.mjs.map +1 -0
  20. package/dist/directory/providers/index.d.ts +3 -0
  21. package/dist/directory/providers/index.d.ts.map +1 -0
  22. package/dist/directory/providers/index.js +10 -0
  23. package/dist/directory/providers/index.js.map +1 -0
  24. package/dist/directory/providers/index.mjs +3 -0
  25. package/dist/directory/providers/index.mjs.map +1 -0
  26. package/dist/directory/providers/source/index.d.ts +27 -0
  27. package/dist/directory/providers/source/index.d.ts.map +1 -0
  28. package/dist/directory/providers/source/index.js +266 -0
  29. package/dist/directory/providers/source/index.js.map +1 -0
  30. package/dist/directory/providers/source/index.mjs +259 -0
  31. package/dist/directory/providers/source/index.mjs.map +1 -0
  32. package/dist/engine/errors.js +39 -0
  33. package/dist/engine/errors.js.map +1 -0
  34. package/dist/engine/errors.mjs +34 -0
  35. package/dist/engine/errors.mjs.map +1 -0
  36. package/dist/engine/index.d.ts +2 -3
  37. package/dist/engine/index.d.ts.map +1 -1
  38. package/dist/engine/index.js +922 -0
  39. package/dist/engine/index.js.map +1 -0
  40. package/dist/engine/index.mjs +917 -0
  41. package/dist/engine/index.mjs.map +1 -0
  42. package/dist/engine/validation/provider.d.ts +2 -2
  43. package/dist/engine/validation/provider.d.ts.map +1 -1
  44. package/dist/engine/validation/provider.js +19 -0
  45. package/dist/engine/validation/provider.js.map +1 -0
  46. package/dist/engine/validation/provider.mjs +17 -0
  47. package/dist/engine/validation/provider.mjs.map +1 -0
  48. package/dist/engine/validation/schemas/index.d.ts.map +1 -1
  49. package/dist/engine/validation/schemas/index.js +59 -0
  50. package/dist/engine/validation/schemas/index.js.map +1 -0
  51. package/dist/engine/validation/schemas/index.mjs +57 -0
  52. package/dist/engine/validation/schemas/index.mjs.map +1 -0
  53. package/dist/errors/base.js +13 -0
  54. package/dist/errors/base.js.map +1 -0
  55. package/dist/errors/base.mjs +11 -0
  56. package/dist/errors/base.mjs.map +1 -0
  57. package/dist/errors/constants.d.ts +1 -1
  58. package/dist/errors/constants.d.ts.map +1 -1
  59. package/dist/errors/constants.js +9 -0
  60. package/dist/errors/constants.js.map +1 -0
  61. package/dist/errors/constants.mjs +7 -0
  62. package/dist/errors/constants.mjs.map +1 -0
  63. package/dist/errors/providers.d.ts +1 -1
  64. package/dist/errors/providers.d.ts.map +1 -1
  65. package/dist/errors/providers.js +41 -0
  66. package/dist/errors/providers.js.map +1 -0
  67. package/dist/errors/providers.mjs +36 -0
  68. package/dist/errors/providers.mjs.map +1 -0
  69. package/dist/file/index.js +8 -0
  70. package/dist/file/index.js.map +1 -0
  71. package/dist/file/index.mjs +3 -0
  72. package/dist/file/index.mjs.map +1 -0
  73. package/dist/file/providers/destination/index.d.ts +3 -5
  74. package/dist/file/providers/destination/index.d.ts.map +1 -1
  75. package/dist/file/providers/destination/index.js +254 -0
  76. package/dist/file/providers/destination/index.js.map +1 -0
  77. package/dist/file/providers/destination/index.mjs +246 -0
  78. package/dist/file/providers/destination/index.mjs.map +1 -0
  79. package/dist/file/providers/destination/utils.d.ts +0 -1
  80. package/dist/file/providers/destination/utils.d.ts.map +1 -1
  81. package/dist/file/providers/destination/utils.js +63 -0
  82. package/dist/file/providers/destination/utils.js.map +1 -0
  83. package/dist/file/providers/destination/utils.mjs +60 -0
  84. package/dist/file/providers/destination/utils.mjs.map +1 -0
  85. package/dist/file/providers/index.js +10 -0
  86. package/dist/file/providers/index.js.map +1 -0
  87. package/dist/file/providers/index.mjs +3 -0
  88. package/dist/file/providers/index.mjs.map +1 -0
  89. package/dist/file/providers/source/index.d.ts +3 -3
  90. package/dist/file/providers/source/index.d.ts.map +1 -1
  91. package/dist/file/providers/source/index.js +336 -0
  92. package/dist/file/providers/source/index.js.map +1 -0
  93. package/dist/file/providers/source/index.mjs +328 -0
  94. package/dist/file/providers/source/index.mjs.map +1 -0
  95. package/dist/file/providers/source/utils.d.ts.map +1 -1
  96. package/dist/file/providers/source/utils.js +60 -0
  97. package/dist/file/providers/source/utils.js.map +1 -0
  98. package/dist/file/providers/source/utils.mjs +52 -0
  99. package/dist/file/providers/source/utils.mjs.map +1 -0
  100. package/dist/index.d.ts +1 -0
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +15 -4408
  103. package/dist/index.js.map +1 -1
  104. package/dist/index.mjs +10 -4382
  105. package/dist/index.mjs.map +1 -1
  106. package/dist/strapi/index.js +12 -0
  107. package/dist/strapi/index.js.map +1 -0
  108. package/dist/strapi/index.mjs +7 -0
  109. package/dist/strapi/index.mjs.map +1 -0
  110. package/dist/strapi/providers/index.js +18 -0
  111. package/dist/strapi/providers/index.js.map +1 -0
  112. package/dist/strapi/providers/index.mjs +8 -0
  113. package/dist/strapi/providers/index.mjs.map +1 -0
  114. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts +26 -0
  115. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts.map +1 -0
  116. package/dist/strapi/providers/local-destination/assets-destination-writable.js +125 -0
  117. package/dist/strapi/providers/local-destination/assets-destination-writable.js.map +1 -0
  118. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs +123 -0
  119. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs.map +1 -0
  120. package/dist/strapi/providers/local-destination/index.d.ts +5 -3
  121. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
  122. package/dist/strapi/providers/local-destination/index.js +362 -0
  123. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  124. package/dist/strapi/providers/local-destination/index.mjs +335 -0
  125. package/dist/strapi/providers/local-destination/index.mjs.map +1 -0
  126. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -2
  127. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
  128. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +58 -0
  129. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  130. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +51 -0
  131. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -0
  132. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -2
  133. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
  134. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +54 -0
  135. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  136. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +52 -0
  137. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -0
  138. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -1
  139. package/dist/strapi/providers/local-destination/strategies/restore/index.js +124 -0
  140. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  141. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +120 -0
  142. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -0
  143. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -2
  144. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
  145. package/dist/strapi/providers/local-destination/strategies/restore/links.js +79 -0
  146. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  147. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +77 -0
  148. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -0
  149. package/dist/strapi/providers/local-source/assets.d.ts +8 -2
  150. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
  151. package/dist/strapi/providers/local-source/assets.js +151 -0
  152. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  153. package/dist/strapi/providers/local-source/assets.mjs +147 -0
  154. package/dist/strapi/providers/local-source/assets.mjs.map +1 -0
  155. package/dist/strapi/providers/local-source/configuration.d.ts +0 -1
  156. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
  157. package/dist/strapi/providers/local-source/configuration.js +47 -0
  158. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  159. package/dist/strapi/providers/local-source/configuration.mjs +45 -0
  160. package/dist/strapi/providers/local-source/configuration.mjs.map +1 -0
  161. package/dist/strapi/providers/local-source/entities.d.ts +3 -2
  162. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
  163. package/dist/strapi/providers/local-source/entities.js +66 -0
  164. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  165. package/dist/strapi/providers/local-source/entities.mjs +63 -0
  166. package/dist/strapi/providers/local-source/entities.mjs.map +1 -0
  167. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts +11 -0
  168. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts.map +1 -0
  169. package/dist/strapi/providers/local-source/estimate-asset-totals.js +130 -0
  170. package/dist/strapi/providers/local-source/estimate-asset-totals.js.map +1 -0
  171. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs +128 -0
  172. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs.map +1 -0
  173. package/dist/strapi/providers/local-source/index.d.ts +6 -4
  174. package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
  175. package/dist/strapi/providers/local-source/index.js +186 -0
  176. package/dist/strapi/providers/local-source/index.js.map +1 -0
  177. package/dist/strapi/providers/local-source/index.mjs +183 -0
  178. package/dist/strapi/providers/local-source/index.mjs.map +1 -0
  179. package/dist/strapi/providers/local-source/links.d.ts +0 -1
  180. package/dist/strapi/providers/local-source/links.d.ts.map +1 -1
  181. package/dist/strapi/providers/local-source/links.js +26 -0
  182. package/dist/strapi/providers/local-source/links.js.map +1 -0
  183. package/dist/strapi/providers/local-source/links.mjs +24 -0
  184. package/dist/strapi/providers/local-source/links.mjs.map +1 -0
  185. package/dist/strapi/providers/remote-destination/index.d.ts +13 -5
  186. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
  187. package/dist/strapi/providers/remote-destination/index.js +482 -0
  188. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  189. package/dist/strapi/providers/remote-destination/index.mjs +480 -0
  190. package/dist/strapi/providers/remote-destination/index.mjs.map +1 -0
  191. package/dist/strapi/providers/remote-source/index.d.ts +11 -6
  192. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
  193. package/dist/strapi/providers/remote-source/index.js +538 -0
  194. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  195. package/dist/strapi/providers/remote-source/index.mjs +536 -0
  196. package/dist/strapi/providers/remote-source/index.mjs.map +1 -0
  197. package/dist/strapi/providers/utils.d.ts +22 -16
  198. package/dist/strapi/providers/utils.d.ts.map +1 -1
  199. package/dist/strapi/providers/utils.js +178 -0
  200. package/dist/strapi/providers/utils.js.map +1 -0
  201. package/dist/strapi/providers/utils.mjs +174 -0
  202. package/dist/strapi/providers/utils.mjs.map +1 -0
  203. package/dist/strapi/queries/entity.d.ts.map +1 -1
  204. package/dist/strapi/queries/entity.js +125 -0
  205. package/dist/strapi/queries/entity.js.map +1 -0
  206. package/dist/strapi/queries/entity.mjs +123 -0
  207. package/dist/strapi/queries/entity.mjs.map +1 -0
  208. package/dist/strapi/queries/index.js +10 -0
  209. package/dist/strapi/queries/index.js.map +1 -0
  210. package/dist/strapi/queries/index.mjs +5 -0
  211. package/dist/strapi/queries/index.mjs.map +1 -0
  212. package/dist/strapi/queries/link.d.ts +1 -1
  213. package/dist/strapi/queries/link.d.ts.map +1 -1
  214. package/dist/strapi/queries/link.js +298 -0
  215. package/dist/strapi/queries/link.js.map +1 -0
  216. package/dist/strapi/queries/link.mjs +295 -0
  217. package/dist/strapi/queries/link.mjs.map +1 -0
  218. package/dist/strapi/remote/constants.d.ts.map +1 -1
  219. package/dist/strapi/remote/constants.js +11 -0
  220. package/dist/strapi/remote/constants.js.map +1 -0
  221. package/dist/strapi/remote/constants.mjs +8 -0
  222. package/dist/strapi/remote/constants.mjs.map +1 -0
  223. package/dist/strapi/remote/flows/default.d.ts.map +1 -1
  224. package/dist/strapi/remote/flows/default.js +43 -0
  225. package/dist/strapi/remote/flows/default.js.map +1 -0
  226. package/dist/strapi/remote/flows/default.mjs +41 -0
  227. package/dist/strapi/remote/flows/default.mjs.map +1 -0
  228. package/dist/strapi/remote/flows/index.d.ts +1 -1
  229. package/dist/strapi/remote/flows/index.d.ts.map +1 -1
  230. package/dist/strapi/remote/flows/index.js +54 -0
  231. package/dist/strapi/remote/flows/index.js.map +1 -0
  232. package/dist/strapi/remote/flows/index.mjs +52 -0
  233. package/dist/strapi/remote/flows/index.mjs.map +1 -0
  234. package/dist/strapi/remote/handlers/abstract.d.ts +4 -1
  235. package/dist/strapi/remote/handlers/abstract.d.ts.map +1 -1
  236. package/dist/strapi/remote/handlers/constants.js +10 -0
  237. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  238. package/dist/strapi/remote/handlers/constants.mjs +8 -0
  239. package/dist/strapi/remote/handlers/constants.mjs.map +1 -0
  240. package/dist/strapi/remote/handlers/index.js +12 -0
  241. package/dist/strapi/remote/handlers/index.js.map +1 -0
  242. package/dist/strapi/remote/handlers/index.mjs +4 -0
  243. package/dist/strapi/remote/handlers/index.mjs.map +1 -0
  244. package/dist/strapi/remote/handlers/pull.d.ts +2 -3
  245. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -1
  246. package/dist/strapi/remote/handlers/pull.js +369 -0
  247. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  248. package/dist/strapi/remote/handlers/pull.mjs +367 -0
  249. package/dist/strapi/remote/handlers/pull.mjs.map +1 -0
  250. package/dist/strapi/remote/handlers/push.d.ts +16 -5
  251. package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
  252. package/dist/strapi/remote/handlers/push.js +454 -0
  253. package/dist/strapi/remote/handlers/push.js.map +1 -0
  254. package/dist/strapi/remote/handlers/push.mjs +452 -0
  255. package/dist/strapi/remote/handlers/push.mjs.map +1 -0
  256. package/dist/strapi/remote/handlers/utils.d.ts +1 -2
  257. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
  258. package/dist/strapi/remote/handlers/utils.js +318 -0
  259. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  260. package/dist/strapi/remote/handlers/utils.mjs +312 -0
  261. package/dist/strapi/remote/handlers/utils.mjs.map +1 -0
  262. package/dist/strapi/remote/index.js +10 -0
  263. package/dist/strapi/remote/index.js.map +1 -0
  264. package/dist/strapi/remote/index.mjs +5 -0
  265. package/dist/strapi/remote/index.mjs.map +1 -0
  266. package/dist/strapi/utils/project-settings-logos.d.ts +29 -0
  267. package/dist/strapi/utils/project-settings-logos.d.ts.map +1 -0
  268. package/dist/strapi/utils/project-settings-logos.js +174 -0
  269. package/dist/strapi/utils/project-settings-logos.js.map +1 -0
  270. package/dist/strapi/utils/project-settings-logos.mjs +169 -0
  271. package/dist/strapi/utils/project-settings-logos.mjs.map +1 -0
  272. package/dist/types/common-entities.d.ts +149 -0
  273. package/dist/types/common-entities.d.ts.map +1 -0
  274. package/dist/types/encryption.d.ts +13 -0
  275. package/dist/types/encryption.d.ts.map +1 -0
  276. package/dist/types/index.d.ts +7 -0
  277. package/dist/types/index.d.ts.map +1 -0
  278. package/dist/types/providers.d.ts +49 -0
  279. package/dist/types/providers.d.ts.map +1 -0
  280. package/dist/types/remote/index.d.ts +2 -0
  281. package/dist/types/remote/index.d.ts.map +1 -0
  282. package/dist/types/remote/protocol/auth.d.ts +5 -0
  283. package/dist/types/remote/protocol/auth.d.ts.map +1 -0
  284. package/dist/types/remote/protocol/client/commands.d.ts +37 -0
  285. package/dist/types/remote/protocol/client/commands.d.ts.map +1 -0
  286. package/dist/types/remote/protocol/client/index.d.ts +9 -0
  287. package/dist/types/remote/protocol/client/index.d.ts.map +1 -0
  288. package/dist/types/remote/protocol/client/transfer/action.d.ts +5 -0
  289. package/dist/types/remote/protocol/client/transfer/action.d.ts.map +1 -0
  290. package/dist/types/remote/protocol/client/transfer/index.d.ts +12 -0
  291. package/dist/types/remote/protocol/client/transfer/index.d.ts.map +1 -0
  292. package/dist/types/remote/protocol/client/transfer/pull.d.ts +25 -0
  293. package/dist/types/remote/protocol/client/transfer/pull.d.ts.map +1 -0
  294. package/dist/types/remote/protocol/client/transfer/push.d.ts +29 -0
  295. package/dist/types/remote/protocol/client/transfer/push.d.ts.map +1 -0
  296. package/dist/types/remote/protocol/client/transfer/utils.d.ts +47 -0
  297. package/dist/types/remote/protocol/client/transfer/utils.d.ts.map +1 -0
  298. package/dist/types/remote/protocol/index.d.ts +4 -0
  299. package/dist/types/remote/protocol/index.d.ts.map +1 -0
  300. package/dist/types/remote/protocol/server/error.d.ts +18 -0
  301. package/dist/types/remote/protocol/server/error.d.ts.map +1 -0
  302. package/dist/types/remote/protocol/server/index.d.ts +3 -0
  303. package/dist/types/remote/protocol/server/index.d.ts.map +1 -0
  304. package/dist/types/remote/protocol/server/messaging.d.ts +37 -0
  305. package/dist/types/remote/protocol/server/messaging.d.ts.map +1 -0
  306. package/dist/types/transfer-engine.d.ts +148 -0
  307. package/dist/types/transfer-engine.d.ts.map +1 -0
  308. package/dist/types/utils.d.ts +82 -0
  309. package/dist/types/utils.d.ts.map +1 -0
  310. package/dist/utils/components.d.ts +23 -3
  311. package/dist/utils/components.d.ts.map +1 -1
  312. package/dist/utils/components.js +230 -0
  313. package/dist/utils/components.js.map +1 -0
  314. package/dist/utils/components.mjs +219 -0
  315. package/dist/utils/components.mjs.map +1 -0
  316. package/dist/{engine → utils}/diagnostic.d.ts +1 -0
  317. package/dist/utils/diagnostic.d.ts.map +1 -0
  318. package/dist/utils/diagnostic.js +51 -0
  319. package/dist/utils/diagnostic.js.map +1 -0
  320. package/dist/utils/diagnostic.mjs +49 -0
  321. package/dist/utils/diagnostic.mjs.map +1 -0
  322. package/dist/utils/encryption/decrypt.d.ts +6 -5
  323. package/dist/utils/encryption/decrypt.d.ts.map +1 -1
  324. package/dist/utils/encryption/decrypt.js +47 -0
  325. package/dist/utils/encryption/decrypt.js.map +1 -0
  326. package/dist/utils/encryption/decrypt.mjs +45 -0
  327. package/dist/utils/encryption/decrypt.mjs.map +1 -0
  328. package/dist/utils/encryption/encrypt.d.ts +6 -5
  329. package/dist/utils/encryption/encrypt.d.ts.map +1 -1
  330. package/dist/utils/encryption/encrypt.js +47 -0
  331. package/dist/utils/encryption/encrypt.js.map +1 -0
  332. package/dist/utils/encryption/encrypt.mjs +45 -0
  333. package/dist/utils/encryption/encrypt.mjs.map +1 -0
  334. package/dist/utils/encryption/index.js +10 -0
  335. package/dist/utils/encryption/index.js.map +1 -0
  336. package/dist/utils/encryption/index.mjs +3 -0
  337. package/dist/utils/encryption/index.mjs.map +1 -0
  338. package/dist/utils/index.d.ts +3 -0
  339. package/dist/utils/index.d.ts.map +1 -1
  340. package/dist/utils/index.js +28 -0
  341. package/dist/utils/index.js.map +1 -0
  342. package/dist/utils/index.mjs +17 -0
  343. package/dist/utils/index.mjs.map +1 -0
  344. package/dist/utils/json.d.ts.map +1 -1
  345. package/dist/utils/json.js +96 -0
  346. package/dist/utils/json.js.map +1 -0
  347. package/dist/utils/json.mjs +94 -0
  348. package/dist/utils/json.mjs.map +1 -0
  349. package/dist/utils/middleware.d.ts +1 -1
  350. package/dist/utils/middleware.d.ts.map +1 -1
  351. package/dist/utils/middleware.js +14 -0
  352. package/dist/utils/middleware.js.map +1 -0
  353. package/dist/utils/middleware.mjs +12 -0
  354. package/dist/utils/middleware.mjs.map +1 -0
  355. package/dist/utils/providers.js +12 -0
  356. package/dist/utils/providers.js.map +1 -0
  357. package/dist/utils/providers.mjs +10 -0
  358. package/dist/utils/providers.mjs.map +1 -0
  359. package/dist/utils/schema.d.ts.map +1 -1
  360. package/dist/utils/schema.js +32 -0
  361. package/dist/utils/schema.js.map +1 -0
  362. package/dist/utils/schema.mjs +29 -0
  363. package/dist/utils/schema.mjs.map +1 -0
  364. package/dist/utils/stream.d.ts +0 -1
  365. package/dist/utils/stream.d.ts.map +1 -1
  366. package/dist/utils/stream.js +96 -0
  367. package/dist/utils/stream.js.map +1 -0
  368. package/dist/utils/stream.mjs +92 -0
  369. package/dist/utils/stream.mjs.map +1 -0
  370. package/dist/utils/transaction.d.ts +1 -1
  371. package/dist/utils/transaction.d.ts.map +1 -1
  372. package/dist/utils/transaction.js +93 -0
  373. package/dist/utils/transaction.js.map +1 -0
  374. package/dist/utils/transaction.mjs +91 -0
  375. package/dist/utils/transaction.mjs.map +1 -0
  376. package/dist/utils/transfer-asset-chunk.d.ts +61 -0
  377. package/dist/utils/transfer-asset-chunk.d.ts.map +1 -0
  378. package/dist/utils/transfer-asset-chunk.js +118 -0
  379. package/dist/utils/transfer-asset-chunk.js.map +1 -0
  380. package/dist/utils/transfer-asset-chunk.mjs +112 -0
  381. package/dist/utils/transfer-asset-chunk.mjs.map +1 -0
  382. package/dist/utils/transfer-websocket-json.d.ts +24 -0
  383. package/dist/utils/transfer-websocket-json.d.ts.map +1 -0
  384. package/dist/utils/transfer-websocket-json.js +67 -0
  385. package/dist/utils/transfer-websocket-json.js.map +1 -0
  386. package/dist/utils/transfer-websocket-json.mjs +63 -0
  387. package/dist/utils/transfer-websocket-json.mjs.map +1 -0
  388. package/dist/utils/writable-async-write.d.ts +16 -0
  389. package/dist/utils/writable-async-write.d.ts.map +1 -0
  390. package/dist/utils/writable-async-write.js +61 -0
  391. package/dist/utils/writable-async-write.js.map +1 -0
  392. package/dist/utils/writable-async-write.mjs +59 -0
  393. package/dist/utils/writable-async-write.mjs.map +1 -0
  394. package/package.json +40 -26
  395. package/dist/engine/diagnostic.d.ts.map +0 -1
@@ -0,0 +1,91 @@
1
+ import { EventEmitter } from 'events';
2
+ import { randomUUID } from 'crypto';
3
+
4
+ const createTransaction = (strapi)=>{
5
+ const fns = [];
6
+ let done = false;
7
+ let resume = null;
8
+ const e = new EventEmitter();
9
+ e.on('spawn', (uuid, cb)=>{
10
+ fns.push({
11
+ fn: cb,
12
+ uuid
13
+ });
14
+ resume?.();
15
+ });
16
+ e.on('close', ()=>{
17
+ e.removeAllListeners('rollback');
18
+ e.removeAllListeners('spawn');
19
+ done = true;
20
+ resume?.();
21
+ });
22
+ strapi.db.transaction(async ({ trx, rollback })=>{
23
+ e.once('rollback', async ()=>{
24
+ e.removeAllListeners('close');
25
+ e.removeAllListeners('spawn');
26
+ try {
27
+ await rollback();
28
+ e.emit('rollback_completed');
29
+ } catch {
30
+ e.emit('rollback_failed');
31
+ } finally{
32
+ done = true;
33
+ resume?.();
34
+ }
35
+ });
36
+ while(!done){
37
+ while(fns.length){
38
+ const item = fns.shift();
39
+ if (item) {
40
+ const { fn, uuid } = item;
41
+ try {
42
+ const res = await fn(trx);
43
+ e.emit(uuid, {
44
+ data: res
45
+ });
46
+ } catch (error) {
47
+ e.emit(uuid, {
48
+ error
49
+ });
50
+ }
51
+ }
52
+ }
53
+ if (!done && !fns.length) {
54
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
55
+ await new Promise((resolve)=>{
56
+ resume = resolve;
57
+ });
58
+ }
59
+ }
60
+ });
61
+ return {
62
+ async attach (callback) {
63
+ const uuid = randomUUID();
64
+ e.emit('spawn', uuid, callback);
65
+ return new Promise((resolve, reject)=>{
66
+ e.on(uuid, ({ data, error })=>{
67
+ if (data) {
68
+ resolve(data);
69
+ }
70
+ if (error) {
71
+ reject(error);
72
+ }
73
+ resolve(undefined);
74
+ });
75
+ });
76
+ },
77
+ end () {
78
+ return e.emit('close');
79
+ },
80
+ rollback () {
81
+ return new Promise((resolve)=>{
82
+ e.emit('rollback');
83
+ e.once('rollback_failed', ()=>resolve(false));
84
+ e.once('rollback_completed', ()=>resolve(true));
85
+ });
86
+ }
87
+ };
88
+ };
89
+
90
+ export { createTransaction };
91
+ //# sourceMappingURL=transaction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.mjs","sources":["../../src/utils/transaction.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { randomUUID } from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { Transaction, TransactionCallback } from '../types/utils';\n\nexport const createTransaction = (strapi: Core.Strapi): Transaction => {\n const fns: { fn: TransactionCallback; uuid: string }[] = [];\n\n let done = false;\n let resume: null | (() => void) = null;\n\n const e = new EventEmitter();\n e.on('spawn', (uuid, cb) => {\n fns.push({ fn: cb, uuid });\n resume?.();\n });\n\n e.on('close', () => {\n e.removeAllListeners('rollback');\n e.removeAllListeners('spawn');\n\n done = true;\n resume?.();\n });\n\n strapi.db.transaction(async ({ trx, rollback }) => {\n e.once('rollback', async () => {\n e.removeAllListeners('close');\n e.removeAllListeners('spawn');\n\n try {\n await rollback();\n e.emit('rollback_completed');\n } catch {\n e.emit('rollback_failed');\n } finally {\n done = true;\n resume?.();\n }\n });\n\n while (!done) {\n while (fns.length) {\n const item = fns.shift();\n\n if (item) {\n const { fn, uuid } = item;\n\n try {\n const res = await fn(trx);\n e.emit(uuid, { data: res });\n } catch (error) {\n e.emit(uuid, { error });\n }\n }\n }\n if (!done && !fns.length) {\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n await new Promise<void>((resolve) => {\n resume = resolve;\n });\n }\n }\n });\n\n return {\n async attach<T = undefined>(callback: TransactionCallback): Promise<T | undefined> {\n const uuid = randomUUID();\n e.emit('spawn', uuid, callback);\n return new Promise<T | undefined>((resolve, reject) => {\n e.on(uuid, ({ data, error }) => {\n if (data) {\n resolve(data);\n }\n\n if (error) {\n reject(error);\n }\n resolve(undefined);\n });\n });\n },\n\n end() {\n return e.emit('close');\n },\n\n rollback() {\n return new Promise<boolean>((resolve) => {\n e.emit('rollback');\n\n e.once('rollback_failed', () => resolve(false));\n e.once('rollback_completed', () => resolve(true));\n });\n },\n };\n};\n"],"names":["createTransaction","strapi","fns","done","resume","e","EventEmitter","on","uuid","cb","push","fn","removeAllListeners","db","transaction","trx","rollback","once","emit","length","item","shift","res","data","error","Promise","resolve","attach","callback","randomUUID","reject","undefined","end"],"mappings":";;;AAMO,MAAMA,oBAAoB,CAACC,MAAAA,GAAAA;AAChC,IAAA,MAAMC,MAAmD,EAAE;AAE3D,IAAA,IAAIC,IAAAA,GAAO,KAAA;AACX,IAAA,IAAIC,MAAAA,GAA8B,IAAA;AAElC,IAAA,MAAMC,IAAI,IAAIC,YAAAA,EAAAA;AACdD,IAAAA,CAAAA,CAAEE,EAAE,CAAC,OAAA,EAAS,CAACC,IAAAA,EAAMC,EAAAA,GAAAA;AACnBP,QAAAA,GAAAA,CAAIQ,IAAI,CAAC;YAAEC,EAAAA,EAAIF,EAAAA;AAAID,YAAAA;AAAK,SAAA,CAAA;AACxBJ,QAAAA,MAAAA,IAAAA;AACF,IAAA,CAAA,CAAA;IAEAC,CAAAA,CAAEE,EAAE,CAAC,OAAA,EAAS,IAAA;AACZF,QAAAA,CAAAA,CAAEO,kBAAkB,CAAC,UAAA,CAAA;AACrBP,QAAAA,CAAAA,CAAEO,kBAAkB,CAAC,OAAA,CAAA;QAErBT,IAAAA,GAAO,IAAA;AACPC,QAAAA,MAAAA,IAAAA;AACF,IAAA,CAAA,CAAA;IAEAH,MAAAA,CAAOY,E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+ * Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.
4
+ */
5
+ export declare function createTransferAssetStreamChunk(assetID: string, chunk: Buffer | Uint8Array): {
6
+ action: 'stream';
7
+ assetID: string;
8
+ encoding: 'base64';
9
+ data: string;
10
+ };
11
+ /**
12
+ * Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`
13
+ * in their push handler. Used only when init negotiation indicates the remote does not understand
14
+ * {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`
15
+ * would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).
16
+ *
17
+ * `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket
18
+ * replacer passes through untouched, so the receiver sees the same shape the old default
19
+ * `JSON.stringify(Buffer)` used to produce.
20
+ *
21
+ * Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during
22
+ * `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation
23
+ * proves the remote cannot decode base64.
24
+ */
25
+ export declare function createTransferAssetStreamChunkLegacy(assetID: string, chunk: Buffer | Uint8Array): {
26
+ action: 'stream';
27
+ assetID: string;
28
+ data: {
29
+ type: 'Buffer';
30
+ data: number[];
31
+ };
32
+ };
33
+ /**
34
+ * Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers
35
+ * and the remote source provider).
36
+ */
37
+ export declare function decodeTransferAssetStreamItem(item: {
38
+ action: 'stream';
39
+ data: unknown;
40
+ encoding?: 'base64';
41
+ }): Buffer;
42
+ /**
43
+ * Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.
44
+ *
45
+ * Supported shapes (receivers should accept all of these):
46
+ * - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).
47
+ * - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default
48
+ * `JSON.stringify` (older clients/servers).
49
+ * - **`Buffer` instance:** in-process only.
50
+ *
51
+ * Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`
52
+ * values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).
53
+ */
54
+ export declare function decodeTransferAssetStreamData(data: unknown, encoding?: 'base64'): Buffer;
55
+ /** Approximate decoded byte size for batching (pull asset generator). */
56
+ export declare function transferAssetStreamChunkByteLength(chunk: {
57
+ action: string;
58
+ data?: unknown;
59
+ encoding?: 'base64';
60
+ }): number;
61
+ //# sourceMappingURL=transfer-asset-chunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-asset-chunk.d.ts","sourceRoot":"","sources":["../../src/utils/transfer-asset-chunk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,UAAU,GACzB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAazE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,UAAU,GACzB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAYjF;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,MAAM,EAAE,QAAQ,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,MAAM,CAKT;AAgBD;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAsBxF;AAED,yEAAyE;AACzE,wBAAgB,kCAAkC,CAAC,KAAK,EAAE;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,MAAM,CAqBT"}
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Canonical **outbound** asset chunk for WebSocket JSON (push and pull).
5
+ * Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.
6
+ */ function createTransferAssetStreamChunk(assetID, chunk) {
7
+ if (chunk == null) {
8
+ throw new TypeError('Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))');
9
+ }
10
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
11
+ return {
12
+ action: 'stream',
13
+ assetID,
14
+ encoding: 'base64',
15
+ data: buffer.toString('base64')
16
+ };
17
+ }
18
+ /**
19
+ * Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`
20
+ * in their push handler. Used only when init negotiation indicates the remote does not understand
21
+ * {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`
22
+ * would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).
23
+ *
24
+ * `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket
25
+ * replacer passes through untouched, so the receiver sees the same shape the old default
26
+ * `JSON.stringify(Buffer)` used to produce.
27
+ *
28
+ * Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during
29
+ * `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation
30
+ * proves the remote cannot decode base64.
31
+ */ function createTransferAssetStreamChunkLegacy(assetID, chunk) {
32
+ if (chunk == null) {
33
+ throw new TypeError('Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))');
34
+ }
35
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
36
+ return {
37
+ action: 'stream',
38
+ assetID,
39
+ data: buffer.toJSON()
40
+ };
41
+ }
42
+ /**
43
+ * Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers
44
+ * and the remote source provider).
45
+ */ function decodeTransferAssetStreamItem(item) {
46
+ return decodeTransferAssetStreamData(item.data, item.encoding === 'base64' ? 'base64' : undefined);
47
+ }
48
+ const getLegacyBufferJsonData = (value)=>{
49
+ if (!value || typeof value !== 'object' || !('type' in value)) {
50
+ return null;
51
+ }
52
+ if (value.type !== 'Buffer') {
53
+ return null;
54
+ }
55
+ const raw = value.data;
56
+ if (Array.isArray(raw) || ArrayBuffer.isView(raw)) {
57
+ return raw;
58
+ }
59
+ return null;
60
+ };
61
+ /**
62
+ * Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.
63
+ *
64
+ * Supported shapes (receivers should accept all of these):
65
+ * - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).
66
+ * - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default
67
+ * `JSON.stringify` (older clients/servers).
68
+ * - **`Buffer` instance:** in-process only.
69
+ *
70
+ * Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`
71
+ * values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).
72
+ */ function decodeTransferAssetStreamData(data, encoding) {
73
+ if (encoding === 'base64' && typeof data === 'string') {
74
+ return Buffer.from(data, 'base64');
75
+ }
76
+ // `encoding: 'base64'` with a non-string payload (or no encoding) uses the same fallbacks as
77
+ // legacy peers — avoids throwing when flags and payload disagree.
78
+ if (Buffer.isBuffer(data)) {
79
+ return Buffer.from(data);
80
+ }
81
+ const legacyBufferData = getLegacyBufferJsonData(data);
82
+ if (legacyBufferData) {
83
+ return Buffer.from(legacyBufferData);
84
+ }
85
+ // Wire base64 string (pull generator and any other path that stringifies a string payload).
86
+ if (typeof data === 'string') {
87
+ return Buffer.from(data, 'base64');
88
+ }
89
+ throw new TypeError('Invalid transfer asset stream chunk payload');
90
+ }
91
+ /** Approximate decoded byte size for batching (pull asset generator). */ function transferAssetStreamChunkByteLength(chunk) {
92
+ if (chunk.action !== 'stream') {
93
+ return 0;
94
+ }
95
+ if (typeof chunk.data === 'string') {
96
+ return Math.floor(chunk.data.length * 3 / 4);
97
+ }
98
+ if (Buffer.isBuffer(chunk.data)) {
99
+ return chunk.data.byteLength;
100
+ }
101
+ const legacyBufferData = getLegacyBufferJsonData(chunk.data);
102
+ if (legacyBufferData) {
103
+ if (Array.isArray(legacyBufferData)) {
104
+ return legacyBufferData.length;
105
+ }
106
+ if (ArrayBuffer.isView(legacyBufferData)) {
107
+ return legacyBufferData.byteLength;
108
+ }
109
+ }
110
+ return 0;
111
+ }
112
+
113
+ exports.createTransferAssetStreamChunk = createTransferAssetStreamChunk;
114
+ exports.createTransferAssetStreamChunkLegacy = createTransferAssetStreamChunkLegacy;
115
+ exports.decodeTransferAssetStreamData = decodeTransferAssetStreamData;
116
+ exports.decodeTransferAssetStreamItem = decodeTransferAssetStreamItem;
117
+ exports.transferAssetStreamChunkByteLength = transferAssetStreamChunkByteLength;
118
+ //# sourceMappingURL=transfer-asset-chunk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-asset-chunk.js","sources":["../../src/utils/transfer-asset-chunk.ts"],"sourcesContent":["/**\n * Canonical **outbound** asset chunk for WebSocket JSON (push and pull).\n * Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.\n */\nexport function createTransferAssetStreamChunk(\n assetID: string,\n chunk: Buffer | Uint8Array\n): { action: 'stream'; assetID: string; encoding: 'base64'; data: string } {\n if (chunk == null) {\n throw new TypeError(\n 'Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))'\n );\n }\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n return {\n action: 'stream',\n assetID,\n encoding: 'base64',\n data: buffer.toString('base64'),\n };\n}\n\n/**\n * Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`\n * in their push handler. Used only when init negotiation indicates the remote does not understand\n * {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`\n * would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).\n *\n * `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket\n * replacer passes through untouched, so the receiver sees the same shape the old default\n * `JSON.stringify(Buffer)` used to produce.\n *\n * Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during\n * `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation\n * proves the remote cannot decode base64.\n */\nexport function createTransferAssetStreamChunkLegacy(\n assetID: string,\n chunk: Buffer | Uint8Array\n): { action: 'stream'; assetID: string; data: { type: 'Buffer'; data: number[] } } {\n if (chunk == null) {\n throw new TypeError(\n 'Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))'\n );\n }\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n return {\n action: 'stream',\n assetID,\n data: buffer.toJSON(),\n };\n}\n\n/**\n * Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers\n * and the remote source provider).\n */\nexport function decodeTransferAssetStreamItem(item: {\n action: 'stream';\n data: unknown;\n encoding?: 'base64';\n}): Buffer {\n return decodeTransferAssetStreamData(\n item.data,\n item.encoding === 'base64' ? 'base64' : undefined\n );\n}\n\nconst getLegacyBufferJsonData = (value: unknown): Uint8Array | readonly number[] | null => {\n if (!value || typeof value !== 'object' || !('type' in value)) {\n return null;\n }\n if ((value as { type: unknown }).type !== 'Buffer') {\n return null;\n }\n const raw = (value as { data?: unknown }).data;\n if (Array.isArray(raw) || ArrayBuffer.isView(raw)) {\n return raw as Uint8Array | readonly number[];\n }\n return null;\n};\n\n/**\n * Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.\n *\n * Supported shapes (receivers should accept all of these):\n * - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).\n * - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default\n * `JSON.stringify` (older clients/servers).\n * - **`Buffer` instance:** in-process only.\n *\n * Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`\n * values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).\n */\nexport function decodeTransferAssetStreamData(data: unknown, encoding?: 'base64'): Buffer {\n if (encoding === 'base64' && typeof data === 'string') {\n return Buffer.from(data, 'base64');\n }\n // `encoding: 'base64'` with a non-string payload (or no encoding) uses the same fallbacks as\n // legacy peers — avoids throwing when flags and payload disagree.\n\n if (Buffer.isBuffer(data)) {\n return Buffer.from(data);\n }\n\n const legacyBufferData = getLegacyBufferJsonData(data);\n if (legacyBufferData) {\n return Buffer.from(legacyBufferData);\n }\n\n // Wire base64 string (pull generator and any other path that stringifies a string payload).\n if (typeof data === 'string') {\n return Buffer.from(data, 'base64');\n }\n\n throw new TypeError('Invalid transfer asset stream chunk payload');\n}\n\n/** Approximate decoded byte size for batching (pull asset generator). */\nexport function transferAssetStreamChunkByteLength(chunk: {\n action: string;\n data?: unknown;\n encoding?: 'base64';\n}): number {\n if (chunk.action !== 'stream') {\n return 0;\n }\n if (typeof chunk.data === 'string') {\n return Math.floor((chunk.data.length * 3) / 4);\n }\n if (Buffer.isBuffer(chunk.data)) {\n return chunk.data.byteLength;\n }\n\n const legacyBufferData = getLegacyBufferJsonData(chunk.data);\n if (legacyBufferData) {\n if (Array.isArray(legacyBufferData)) {\n return legacyBufferData.length;\n }\n if (ArrayBuffer.isView(legacyBufferData)) {\n return legacyBufferData.byteLength;\n }\n }\n return 0;\n}\n"],"names":["createTransferAssetStreamChunk","assetID","chunk","TypeError","buffer","Buffer","isBuffer","from","action","encoding","data","toString","createTransferAssetStreamChunkLegacy","toJSON","decodeTransferAssetStreamItem","item","decodeTransferAssetStreamData","undefined","getLegacyBufferJsonData","value","type","raw","Array","isArray","ArrayBuffer","isView","legacyBufferData","transferAssetStreamChunkByteLength","Math","floor","length","byteLength"],"mappings":";;AAAA;;;AAGC,IACM,SAASA,8BAAAA,CACdC,OAAe,EACfC,KAA0B,EAAA;AAE1B,IAAA,IAAIA,SAAS,IAAA,EAAM;AACjB,QAAA,MAAM,IAAIC,SAAAA,CACR,wGAAA,CAAA;AAEJ,IAAA;IACA,MAAMC,MAAAA,GAASC,OAAOC,QAAQ,CAACJ,SAASA,KAAAA,GAAQG,MAAAA,CAAOE,IAAI,CAACL,KAAAA,CAAAA;IAC5D,OAAO;QACLM,MAAAA,EAAQ,QAAA;AACRP,QAAAA,OAAAA;QACAQ,QAAAA,EAAU,QAAA;QACVC,IAAAA,EAAMN,MAAAA,CAAOO,QAAQ,CAAC,QAAA;AACxB,KAAA;AACF;AAEA;;;;;;;;;;;;;AAaC,IACM,SAASC,oCAAAA,CACdX,OAAe,EACfC,KAA0B,EAAA;AAE1B,IAAA,IAAIA,SAAS,IAAA,EAAM;AACjB,QAAA,MAAM,IAAIC,SAAAA,CACR,wGAAA,CAAA;AAEJ,IAAA;IACA,MAAMC,MAAAA,GAASC,OAAOC,QAAQ,CAACJ,SAASA,KAAAA,GAAQG,MAAAA,CAAOE,IAAI,CAACL,KAAAA,CAAAA;IAC5D,OAAO;QACLM,MAAAA,EAAQ,QAAA;AACRP,QAAAA,OAAAA;AACAS,QAAAA,IAAAA,EAAMN,OAAOS,MAAM;AACrB,KAAA;AACF;AAEA;;;IAIO,SAASC,6BAAAA,CAA8BC,IAI7C,EAAA;IACC,OAAOC,6BAAAA,CACLD,KAAKL,IAAI,EACTK,KAAKN,QAAQ,KAAK,WAAW,QAAA,GAAWQ,SAAAA,CAAAA;AAE5C;AAEA,MAAMC,0BAA0B,CAACC,KAAAA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,CAAA;AACT,IAAA;AACA,IAAA,IAAI,OAAON,KAAAA,CAAMQ,IAAI,KAAK,QAAA,EAAU;QAClC,OAAOkB,IAAAA,CAAKC,KAAK,CAAE3B,MAAMQ,IAAI,CAACoB,MAAM,GAAG,CAAA,GAAK,CAAA,CAAA;AAC9C,IAAA;AACA,IAAA,IAAIzB,MAAAA,CAAOC,QAAQ,CAACJ,KAAAA,CAAMQ,IAAI,CAAA,EAAG;QAC/B,OAAOR,KAAAA,CAAMQ,IAAI,CAACqB,UAAU;AAC9B,IAAA;IAEA,MAAML,gBAAAA,GAAmBR,uBAAAA,CAAwBhB,KAAAA,CAAMQ,IAAI,CAAA;AAC3D,IAAA,IAAIgB,gBAAAA,EAAkB;QACpB,IAAIJ,KAAAA,CAAMC,OAAO,CAACG,gBAAAA,CAAAA,EAAmB;AACnC,YAAA,OAAOA,iBAAiBI,MAAM;AAChC,QAAA;QACA,IAAIN,WAAAA,CAAYC,MAAM,CAACC,gBAAAA,CAAAA,EAAmB;AACxC,YAAA,OAAOA,iBAAiBK,UAAU;AACpC,QAAA;AACF,IAAA;IACA,OAAO,CAAA;AACT;;;;;;;;"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Canonical **outbound** asset chunk for WebSocket JSON (push and pull).
3
+ * Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.
4
+ */ function createTransferAssetStreamChunk(assetID, chunk) {
5
+ if (chunk == null) {
6
+ throw new TypeError('Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))');
7
+ }
8
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
9
+ return {
10
+ action: 'stream',
11
+ assetID,
12
+ encoding: 'base64',
13
+ data: buffer.toString('base64')
14
+ };
15
+ }
16
+ /**
17
+ * Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`
18
+ * in their push handler. Used only when init negotiation indicates the remote does not understand
19
+ * {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`
20
+ * would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).
21
+ *
22
+ * `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket
23
+ * replacer passes through untouched, so the receiver sees the same shape the old default
24
+ * `JSON.stringify(Buffer)` used to produce.
25
+ *
26
+ * Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during
27
+ * `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation
28
+ * proves the remote cannot decode base64.
29
+ */ function createTransferAssetStreamChunkLegacy(assetID, chunk) {
30
+ if (chunk == null) {
31
+ throw new TypeError('Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))');
32
+ }
33
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
34
+ return {
35
+ action: 'stream',
36
+ assetID,
37
+ data: buffer.toJSON()
38
+ };
39
+ }
40
+ /**
41
+ * Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers
42
+ * and the remote source provider).
43
+ */ function decodeTransferAssetStreamItem(item) {
44
+ return decodeTransferAssetStreamData(item.data, item.encoding === 'base64' ? 'base64' : undefined);
45
+ }
46
+ const getLegacyBufferJsonData = (value)=>{
47
+ if (!value || typeof value !== 'object' || !('type' in value)) {
48
+ return null;
49
+ }
50
+ if (value.type !== 'Buffer') {
51
+ return null;
52
+ }
53
+ const raw = value.data;
54
+ if (Array.isArray(raw) || ArrayBuffer.isView(raw)) {
55
+ return raw;
56
+ }
57
+ return null;
58
+ };
59
+ /**
60
+ * Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.
61
+ *
62
+ * Supported shapes (receivers should accept all of these):
63
+ * - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).
64
+ * - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default
65
+ * `JSON.stringify` (older clients/servers).
66
+ * - **`Buffer` instance:** in-process only.
67
+ *
68
+ * Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`
69
+ * values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).
70
+ */ function decodeTransferAssetStreamData(data, encoding) {
71
+ if (encoding === 'base64' && typeof data === 'string') {
72
+ return Buffer.from(data, 'base64');
73
+ }
74
+ // `encoding: 'base64'` with a non-string payload (or no encoding) uses the same fallbacks as
75
+ // legacy peers — avoids throwing when flags and payload disagree.
76
+ if (Buffer.isBuffer(data)) {
77
+ return Buffer.from(data);
78
+ }
79
+ const legacyBufferData = getLegacyBufferJsonData(data);
80
+ if (legacyBufferData) {
81
+ return Buffer.from(legacyBufferData);
82
+ }
83
+ // Wire base64 string (pull generator and any other path that stringifies a string payload).
84
+ if (typeof data === 'string') {
85
+ return Buffer.from(data, 'base64');
86
+ }
87
+ throw new TypeError('Invalid transfer asset stream chunk payload');
88
+ }
89
+ /** Approximate decoded byte size for batching (pull asset generator). */ function transferAssetStreamChunkByteLength(chunk) {
90
+ if (chunk.action !== 'stream') {
91
+ return 0;
92
+ }
93
+ if (typeof chunk.data === 'string') {
94
+ return Math.floor(chunk.data.length * 3 / 4);
95
+ }
96
+ if (Buffer.isBuffer(chunk.data)) {
97
+ return chunk.data.byteLength;
98
+ }
99
+ const legacyBufferData = getLegacyBufferJsonData(chunk.data);
100
+ if (legacyBufferData) {
101
+ if (Array.isArray(legacyBufferData)) {
102
+ return legacyBufferData.length;
103
+ }
104
+ if (ArrayBuffer.isView(legacyBufferData)) {
105
+ return legacyBufferData.byteLength;
106
+ }
107
+ }
108
+ return 0;
109
+ }
110
+
111
+ export { createTransferAssetStreamChunk, createTransferAssetStreamChunkLegacy, decodeTransferAssetStreamData, decodeTransferAssetStreamItem, transferAssetStreamChunkByteLength };
112
+ //# sourceMappingURL=transfer-asset-chunk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-asset-chunk.mjs","sources":["../../src/utils/transfer-asset-chunk.ts"],"sourcesContent":["/**\n * Canonical **outbound** asset chunk for WebSocket JSON (push and pull).\n * Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.\n */\nexport function createTransferAssetStreamChunk(\n assetID: string,\n chunk: Buffer | Uint8Array\n): { action: 'stream'; assetID: string; encoding: 'base64'; data: string } {\n if (chunk == null) {\n throw new TypeError(\n 'Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))'\n );\n }\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n return {\n action: 'stream',\n assetID,\n encoding: 'base64',\n data: buffer.toString('base64'),\n };\n}\n\n/**\n * Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`\n * in their push handler. Used only when init negotiation indicates the remote does not understand\n * {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`\n * would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).\n *\n * `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket\n * replacer passes through untouched, so the receiver sees the same shape the old default\n * `JSON.stringify(Buffer)` used to produce.\n *\n * Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during\n * `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation\n * proves the remote cannot decode base64.\n */\nexport function createTransferAssetStreamChunkLegacy(\n assetID: string,\n chunk: Buffer | Uint8Array\n): { action: 'stream'; assetID: string; data: { type: 'Buffer'; data: number[] } } {\n if (chunk == null) {\n throw new TypeError(\n 'Asset stream yielded a null/undefined chunk; refusing to encode (would trigger Buffer.from(undefined))'\n );\n }\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n return {\n action: 'stream',\n assetID,\n data: buffer.toJSON(),\n };\n}\n\n/**\n * Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers\n * and the remote source provider).\n */\nexport function decodeTransferAssetStreamItem(item: {\n action: 'stream';\n data: unknown;\n encoding?: 'base64';\n}): Buffer {\n return decodeTransferAssetStreamData(\n item.data,\n item.encoding === 'base64' ? 'base64' : undefined\n );\n}\n\nconst getLegacyBufferJsonData = (value: unknown): Uint8Array | readonly number[] | null => {\n if (!value || typeof value !== 'object' || !('type' in value)) {\n return null;\n }\n if ((value as { type: unknown }).type !== 'Buffer') {\n return null;\n }\n const raw = (value as { data?: unknown }).data;\n if (Array.isArray(raw) || ArrayBuffer.isView(raw)) {\n return raw as Uint8Array | readonly number[];\n }\n return null;\n};\n\n/**\n * Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.\n *\n * Supported shapes (receivers should accept all of these):\n * - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).\n * - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default\n * `JSON.stringify` (older clients/servers).\n * - **`Buffer` instance:** in-process only.\n *\n * Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`\n * values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).\n */\nexport function decodeTransferAssetStreamData(data: unknown, encoding?: 'base64'): Buffer {\n if (encoding === 'base64' && typeof data === 'string') {\n return Buffer.from(data, 'base64');\n }\n // `encoding: 'base64'` with a non-string payload (or no encoding) uses the same fallbacks as\n // legacy peers — avoids throwing when flags and payload disagree.\n\n if (Buffer.isBuffer(data)) {\n return Buffer.from(data);\n }\n\n const legacyBufferData = getLegacyBufferJsonData(data);\n if (legacyBufferData) {\n return Buffer.from(legacyBufferData);\n }\n\n // Wire base64 string (pull generator and any other path that stringifies a string payload).\n if (typeof data === 'string') {\n return Buffer.from(data, 'base64');\n }\n\n throw new TypeError('Invalid transfer asset stream chunk payload');\n}\n\n/** Approximate decoded byte size for batching (pull asset generator). */\nexport function transferAssetStreamChunkByteLength(chunk: {\n action: string;\n data?: unknown;\n encoding?: 'base64';\n}): number {\n if (chunk.action !== 'stream') {\n return 0;\n }\n if (typeof chunk.data === 'string') {\n return Math.floor((chunk.data.length * 3) / 4);\n }\n if (Buffer.isBuffer(chunk.data)) {\n return chunk.data.byteLength;\n }\n\n const legacyBufferData = getLegacyBufferJsonData(chunk.data);\n if (legacyBufferData) {\n if (Array.isArray(legacyBufferData)) {\n return legacyBufferData.length;\n }\n if (ArrayBuffer.isView(legacyBufferData)) {\n return legacyBufferData.byteLength;\n }\n }\n return 0;\n}\n"],"names":["createTransferAssetStreamChunk","assetID","chunk","TypeError","buffer","Buffer","isBuffer","from","action","encoding","data","toString","createTransferAssetStreamChunkLegacy","toJSON","decodeTransferAssetStreamItem","item","decodeTransferAssetStreamData","undefined","getLegacyBufferJsonData","value","type","raw","Array","isArray","ArrayBuffer","isView","legacyBufferData","transferAssetStreamChunkByteLength","Math","floor","length","byteLength"],"mappings":"AAAA;;;AAGC,IACM,SAASA,8BAAAA,CACdC,OAAe,EACfC,KAA0B,EAAA;AAE1B,IAAA,IAAIA,SAAS,IAAA,EAAM;AACjB,QAAA,MAAM,IAAIC,SAAAA,CACR,wGAAA,CAAA;AAEJ,IAAA;IACA,MAAMC,MAAAA,GAASC,OAAOC,QAAQ,CAACJ,SAASA,KAAAA,GAAQG,MAAAA,CAAOE,IAAI,CAACL,KAAAA,CAAAA;IAC5D,OAAO;QACLM,MAAAA,EAAQ,QAAA;AACRP,QAAAA,OAAAA;QACAQ,QAAAA,EAAU,QAAA;QACVC,IAAAA,EAAMN,MAAAA,CAAOO,QAAQ,CAAC,QAAA;AACxB,KAAA;AACF;AAEA;;;;;;;;;;;;;AAaC,IACM,SAASC,oCAAAA,CACdX,OAAe,EACfC,KAA0B,EAAA;AAE1B,IAAA,IAAIA,SAAS,IAAA,EAAM;AACjB,QAAA,MAAM,IAAIC,SAAAA,CACR,wGAAA,CAAA;AAEJ,IAAA;IACA,MAAMC,MAAAA,GAASC,OAAOC,QAAQ,CAACJ,SAASA,KAAAA,GAAQG,MAAAA,CAAOE,IAAI,CAAC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I,CAACmB,gBAAAA,CAAAA;AACrB,IAAA;;IAGA,IAAI,OAAOhB,SAAS,QAAA,EAAU;QAC5B,OAAOL,MAAAA,CAAOE,IAAI,CAACG,IAAAA,EAAM,QAAA,CAAA;AAC3B,IAAA;AAEA,IAAA,MAAM,IAAIP,SAAAA,CAAU,6CAAA,CAAA;AACtB;AAEA,0EACO,SAASwB,kCAAAA,CAAmCzB,KAIlD,EAAA;IACC,IAAIA,KAAAA,CAAMM,MAAM,KAAK,QAAA,EAAU;QAC7B,OAAO,CAAA;AACT,IAAA;AACA,IAAA,IAAI,OAAON,KAAAA,CAAMQ,IAAI,KAAK,QAAA,EAAU;QAClC,OAAOkB,IAAAA,CAAKC,KAAK,CAAE3B,MAAMQ,IAAI,CAACoB,MAAM,GAAG,CAAA,GAAK,CAAA,CAAA;AAC9C,IAAA;AACA,IAAA,IAAIzB,MAAAA,CAAOC,QAAQ,CAACJ,KAAAA,CAAMQ,IAAI,CAAA,EAAG;QAC/B,OAAOR,KAAAA,CAAMQ,IAAI,CAACqB,UAAU;AAC9B,IAAA;IAEA,MAAML,gBAAAA,GAAmBR,uBAAAA,CAAwBhB,KAAAA,CAAMQ,IAAI,CAAA;AAC3D,IAAA,IAAIgB,gBAAAA,EAAkB;QACpB,IAAIJ,KAAAA,CAAMC,OAAO,CAACG,gBAAAA,CAAAA,EAAmB;AACnC,YAAA,OAAOA,iBAAiBI,MAAM;AAChC,QAAA;QACA,IAAIN,WAAAA,CAAYC,MAAM,CAACC,gBAAAA,CAAAA,EAAmB;AACxC,YAAA,OAAOA,iBAAiBK,UAAU;AACpC,QAAA;AACF,IAAA;IACA,OAAO,CAAA;AACT;;;;"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull).
3
+ *
4
+ * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which
5
+ * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead.
6
+ *
7
+ * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the
8
+ * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see
9
+ * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`).
10
+ */
11
+ export declare const replacerForTransferWebSocket: (_key: string, value: unknown) => unknown;
12
+ /**
13
+ * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that
14
+ * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)`
15
+ * throws ("The first argument must be of type string or an instance of Buffer... Received undefined").
16
+ * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM
17
+ * objects onto the wire payload — strip it on the root object we control.
18
+ */
19
+ export declare function stripRootToJSONMethod(payload: Record<string, unknown>): void;
20
+ /**
21
+ * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`).
22
+ */
23
+ export declare function stringifyTransferWebSocketPayload(payload: Record<string, unknown>): string;
24
+ //# sourceMappingURL=transfer-websocket-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-websocket-json.d.ts","sourceRoot":"","sources":["../../src/utils/transfer-websocket-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GAAI,MAAM,MAAM,EAAE,OAAO,OAAO,KAAG,OA4B3E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAI5E;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAe1F"}
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull).
5
+ *
6
+ * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which
7
+ * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead.
8
+ *
9
+ * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the
10
+ * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see
11
+ * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`).
12
+ */ const replacerForTransferWebSocket = (_key, value)=>{
13
+ /** `JSON.stringify` throws on bigint; upload metadata or ORM fields may surface as BigInt. */ if (typeof value === 'bigint') {
14
+ return value.toString();
15
+ }
16
+ if (Buffer.isBuffer(value)) {
17
+ return value.toString('base64');
18
+ }
19
+ if (value instanceof Uint8Array) {
20
+ const { buffer, byteOffset, byteLength } = value;
21
+ if (buffer == null) {
22
+ throw new TypeError('Invalid Uint8Array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket');
23
+ }
24
+ return Buffer.from(buffer, byteOffset, byteLength).toString('base64');
25
+ }
26
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
27
+ const v = value;
28
+ const { buffer, byteOffset, byteLength } = v;
29
+ if (buffer == null) {
30
+ throw new TypeError('Invalid typed array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket');
31
+ }
32
+ return Buffer.from(buffer, byteOffset, byteLength).toString('base64');
33
+ }
34
+ return value;
35
+ };
36
+ /**
37
+ * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that
38
+ * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)`
39
+ * throws ("The first argument must be of type string or an instance of Buffer... Received undefined").
40
+ * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM
41
+ * objects onto the wire payload — strip it on the root object we control.
42
+ */ function stripRootToJSONMethod(payload) {
43
+ if (typeof payload.toJSON === 'function') {
44
+ delete payload.toJSON;
45
+ }
46
+ }
47
+ /**
48
+ * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`).
49
+ */ function stringifyTransferWebSocketPayload(payload) {
50
+ stripRootToJSONMethod(payload);
51
+ let s;
52
+ try {
53
+ s = JSON.stringify(payload, replacerForTransferWebSocket);
54
+ } catch (err) {
55
+ const message = err instanceof Error ? err.message : String(err);
56
+ throw new TypeError(`Transfer WebSocket payload could not be serialized to JSON: ${message}`);
57
+ }
58
+ if (typeof s !== 'string') {
59
+ throw new TypeError('Transfer WebSocket payload could not be serialized to JSON (result was undefined). Check for Symbol or other non-JSON values on the root payload.');
60
+ }
61
+ return s;
62
+ }
63
+
64
+ exports.replacerForTransferWebSocket = replacerForTransferWebSocket;
65
+ exports.stringifyTransferWebSocketPayload = stringifyTransferWebSocketPayload;
66
+ exports.stripRootToJSONMethod = stripRootToJSONMethod;
67
+ //# sourceMappingURL=transfer-websocket-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-websocket-json.js","sources":["../../src/utils/transfer-websocket-json.ts"],"sourcesContent":["/**\n * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull).\n *\n * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which\n * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead.\n *\n * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the\n * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see\n * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`).\n */\nexport const replacerForTransferWebSocket = (_key: string, value: unknown): unknown => {\n /** `JSON.stringify` throws on bigint; upload metadata or ORM fields may surface as BigInt. */\n if (typeof value === 'bigint') {\n return value.toString();\n }\n if (Buffer.isBuffer(value)) {\n return value.toString('base64');\n }\n if (value instanceof Uint8Array) {\n const { buffer, byteOffset, byteLength } = value;\n if (buffer == null) {\n throw new TypeError(\n 'Invalid Uint8Array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket'\n );\n }\n return Buffer.from(buffer, byteOffset, byteLength).toString('base64');\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const v = value as NodeJS.TypedArray;\n const { buffer, byteOffset, byteLength } = v;\n if (buffer == null) {\n throw new TypeError(\n 'Invalid typed array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket'\n );\n }\n return Buffer.from(buffer, byteOffset, byteLength).toString('base64');\n }\n return value;\n};\n\n/**\n * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that\n * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)`\n * throws (\"The first argument must be of type string or an instance of Buffer... Received undefined\").\n * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM\n * objects onto the wire payload — strip it on the root object we control.\n */\nexport function stripRootToJSONMethod(payload: Record<string, unknown>): void {\n if (typeof payload.toJSON === 'function') {\n delete payload.toJSON;\n }\n}\n\n/**\n * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`).\n */\nexport function stringifyTransferWebSocketPayload(payload: Record<string, unknown>): string {\n stripRootToJSONMethod(payload);\n let s: string | undefined;\n try {\n s = JSON.stringify(payload, replacerForTransferWebSocket);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new TypeError(`Transfer WebSocket payload could not be serialized to JSON: ${message}`);\n }\n if (typeof s !== 'string') {\n throw new TypeError(\n 'Transfer WebSocket payload could not be serialized to JSON (result was undefined). Check for Symbol or other non-JSON values on the root payload.'\n );\n }\n return s;\n}\n"],"names":["replacerForTransferWebSocket","_key","value","toString","Buffer","isBuffer","Uint8Array","buffer","byteOffset","byteLength","TypeError","from","ArrayBuffer","isView","DataView","v","stripRootToJSONMethod","payload","toJSON","stringifyTransferWebSocketPayload","s","JSON","stringify","err","message","Error","String"],"mappings":";;AAAA;;;;;;;;;AASC,IACM,MAAMA,4BAAAA,GAA+B,CAACC,IAAAA,EAAcC,KAAAA,GAAAA;A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AkCF,OAAgC,EAAA;IAChFD,qBAAAA,CAAsBC,OAAAA,CAAAA;IACtB,IAAIG,CAAAA;IACJ,IAAI;QACFA,CAAAA,GAAIC,IAAAA,CAAKC,SAAS,CAACL,OAAAA,EAASjB,4BAAAA,CAAAA;AAC9B,IAAA,CAAA,CAAE,OAAOuB,GAAAA,EAAK;AACZ,QAAA,MAAMC,UAAUD,GAAAA,YAAeE,KAAAA,GAAQF,GAAAA,CAAIC,OAAO,GAAGE,MAAAA,CAAOH,GAAAA,CAAAA;AAC5D,QAAA,MAAM,IAAIb,SAAAA,CAAU,CAAC,4DAA4D,EAAEc,OAAAA,CAAAA,CAAS,CAAA;AAC9F,IAAA;IACA,IAAI,OAAOJ,MAAM,QAAA,EAAU;AACzB,QAAA,MAAM,IAAIV,SAAAA,CACR,mJAAA,CAAA;AAEJ,IAAA;IACA,OAAOU,CAAAA;AACT;;;;;;"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull).
3
+ *
4
+ * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which
5
+ * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead.
6
+ *
7
+ * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the
8
+ * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see
9
+ * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`).
10
+ */ const replacerForTransferWebSocket = (_key, value)=>{
11
+ /** `JSON.stringify` throws on bigint; upload metadata or ORM fields may surface as BigInt. */ if (typeof value === 'bigint') {
12
+ return value.toString();
13
+ }
14
+ if (Buffer.isBuffer(value)) {
15
+ return value.toString('base64');
16
+ }
17
+ if (value instanceof Uint8Array) {
18
+ const { buffer, byteOffset, byteLength } = value;
19
+ if (buffer == null) {
20
+ throw new TypeError('Invalid Uint8Array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket');
21
+ }
22
+ return Buffer.from(buffer, byteOffset, byteLength).toString('base64');
23
+ }
24
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
25
+ const v = value;
26
+ const { buffer, byteOffset, byteLength } = v;
27
+ if (buffer == null) {
28
+ throw new TypeError('Invalid typed array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket');
29
+ }
30
+ return Buffer.from(buffer, byteOffset, byteLength).toString('base64');
31
+ }
32
+ return value;
33
+ };
34
+ /**
35
+ * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that
36
+ * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)`
37
+ * throws ("The first argument must be of type string or an instance of Buffer... Received undefined").
38
+ * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM
39
+ * objects onto the wire payload — strip it on the root object we control.
40
+ */ function stripRootToJSONMethod(payload) {
41
+ if (typeof payload.toJSON === 'function') {
42
+ delete payload.toJSON;
43
+ }
44
+ }
45
+ /**
46
+ * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`).
47
+ */ function stringifyTransferWebSocketPayload(payload) {
48
+ stripRootToJSONMethod(payload);
49
+ let s;
50
+ try {
51
+ s = JSON.stringify(payload, replacerForTransferWebSocket);
52
+ } catch (err) {
53
+ const message = err instanceof Error ? err.message : String(err);
54
+ throw new TypeError(`Transfer WebSocket payload could not be serialized to JSON: ${message}`);
55
+ }
56
+ if (typeof s !== 'string') {
57
+ throw new TypeError('Transfer WebSocket payload could not be serialized to JSON (result was undefined). Check for Symbol or other non-JSON values on the root payload.');
58
+ }
59
+ return s;
60
+ }
61
+
62
+ export { replacerForTransferWebSocket, stringifyTransferWebSocketPayload, stripRootToJSONMethod };
63
+ //# sourceMappingURL=transfer-websocket-json.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-websocket-json.mjs","sources":["../../src/utils/transfer-websocket-json.ts"],"sourcesContent":["/**\n * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull).\n *\n * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which\n * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead.\n *\n * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the\n * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see\n * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`).\n */\nexport const replacerForTransferWebSocket = (_key: string, value: unknown): unknown => {\n /** `JSON.stringify` throws on bigint; upload metadata or ORM fields may surface as BigInt. */\n if (typeof value === 'bigint') {\n return value.toString();\n }\n if (Buffer.isBuffer(value)) {\n return value.toString('base64');\n }\n if (value instanceof Uint8Array) {\n const { buffer, byteOffset, byteLength } = value;\n if (buffer == null) {\n throw new TypeError(\n 'Invalid Uint8Array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket'\n );\n }\n return Buffer.from(buffer, byteOffset, byteLength).toString('base64');\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const v = value as NodeJS.TypedArray;\n const { buffer, byteOffset, byteLength } = v;\n if (buffer == null) {\n throw new TypeError(\n 'Invalid typed array in transfer payload (missing underlying ArrayBuffer); cannot encode for WebSocket'\n );\n }\n return Buffer.from(buffer, byteOffset, byteLength).toString('base64');\n }\n return value;\n};\n\n/**\n * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that\n * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)`\n * throws (\"The first argument must be of type string or an instance of Buffer... Received undefined\").\n * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM\n * objects onto the wire payload — strip it on the root object we control.\n */\nexport function stripRootToJSONMethod(payload: Record<string, unknown>): void {\n if (typeof payload.toJSON === 'function') {\n delete payload.toJSON;\n }\n}\n\n/**\n * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`).\n */\nexport function stringifyTransferWebSocketPayload(payload: Record<string, unknown>): string {\n stripRootToJSONMethod(payload);\n let s: string | undefined;\n try {\n s = JSON.stringify(payload, replacerForTransferWebSocket);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new TypeError(`Transfer WebSocket payload could not be serialized to JSON: ${message}`);\n }\n if (typeof s !== 'string') {\n throw new TypeError(\n 'Transfer WebSocket payload could not be serialized to JSON (result was undefined). Check for Symbol or other non-JSON values on the root payload.'\n );\n }\n return s;\n}\n"],"names":["replacerForTransferWebSocket","_key","value","toString","Buffer","isBuffer","Uint8Array","buffer","byteOffset","byteLength","TypeError","from","ArrayBuffer","isView","DataView","v","stripRootToJSONMethod","payload","toJSON","stringifyTransferWebSocketPayload","s","JSON","stringify","err","message","Error","String"],"mappings":"AAAA;;;;;;;;;AASC,IACM,MAAMA,4BAAAA,GAA+B,CAACC,IAAAA,EAAcC,KAAAA,GAAAA;AACzD,mGACA,IAAI,OAAOA,KAAAA,KAAU,QAAA,EAAU;AAC7B,QAAA,OAAOA,MAAMC,QAAQ,EAAA;AACvB,IAAA;IACA,IAAIC,MAAAA,CAAOC,QAAQ,CAACH,KAAAA,CAAAA,EAAQ;QAC1B,OAAOA,KAAAA,CAAMC,QAAQ,CAAC,QAAA,CAAA;AACxB,IAAA;AACA,IAAA,IAAID,iBAAiBI,UAAAA,EAAY;AAC/B,QAAA,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAE,GAAGP,KAAAA;AAC3C,QAAA,IAAIK,UAAU,IAAA,EAAM;AAClB,YAAA,MAAM,IAAIG,SAAAA,CACR,sGAAA,CAAA;AAEJ,QAAA;AACA,QAAA,OAAON,OAAOO,IAAI,CAACJ,QAAQC,UAAAA,EAAYC,UAAAA,CAAAA,CAAYN,QAAQ,CAAC,QAAA,CAAA;AAC9D,IAAA;IACA,IAAIS,WAAAA,CAAYC,MAAM,CAACX,KAAAA,CAAAA,IAAU,E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