document-model 2.4.0 → 2.5.0-test.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 (637) hide show
  1. package/dist/index.d.ts +18 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +13 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/{browser/src → src}/document/actions/creators.d.ts +4 -2
  6. package/dist/src/document/actions/creators.d.ts.map +1 -0
  7. package/dist/{node/src/document/actions/creators.d.ts → src/document/actions/creators.js} +18 -8
  8. package/dist/src/document/actions/creators.js.map +1 -0
  9. package/dist/src/document/actions/operations.d.ts +23 -0
  10. package/dist/src/document/actions/operations.d.ts.map +1 -0
  11. package/dist/src/document/actions/operations.js +131 -0
  12. package/dist/src/document/actions/operations.js.map +1 -0
  13. package/dist/src/document/actions/types.d.ts +16 -0
  14. package/dist/src/document/actions/types.d.ts.map +1 -0
  15. package/dist/src/document/actions/types.js +7 -0
  16. package/dist/src/document/actions/types.js.map +1 -0
  17. package/dist/{browser/src → src}/document/object.d.ts +17 -14
  18. package/dist/src/document/object.d.ts.map +1 -0
  19. package/dist/{node/src/document/object.d.ts → src/document/object.js} +93 -29
  20. package/dist/src/document/object.js.map +1 -0
  21. package/dist/src/document/reducer.d.ts +49 -0
  22. package/dist/src/document/reducer.d.ts.map +1 -0
  23. package/dist/src/document/reducer.js +342 -0
  24. package/dist/src/document/reducer.js.map +1 -0
  25. package/dist/{browser/src → src}/document/schema/types.d.ts +2 -1
  26. package/dist/src/document/schema/types.d.ts.map +1 -0
  27. package/dist/src/document/schema/types.js +2 -0
  28. package/dist/src/document/schema/types.js.map +1 -0
  29. package/dist/{browser/src → src}/document/schema/zod.d.ts +30 -47
  30. package/dist/src/document/schema/zod.d.ts.map +1 -0
  31. package/dist/src/document/schema/zod.js +113 -0
  32. package/dist/src/document/schema/zod.js.map +1 -0
  33. package/dist/{node/src → src}/document/signal.d.ts +10 -9
  34. package/dist/src/document/signal.d.ts.map +1 -0
  35. package/dist/src/document/signal.js +2 -0
  36. package/dist/src/document/signal.js.map +1 -0
  37. package/dist/src/document/types.d.ts +345 -0
  38. package/dist/src/document/types.d.ts.map +1 -0
  39. package/dist/src/document/types.js +2 -0
  40. package/dist/src/document/types.js.map +1 -0
  41. package/dist/src/document/utils/base.d.ts +83 -0
  42. package/dist/src/document/utils/base.d.ts.map +1 -0
  43. package/dist/src/document/utils/base.js +331 -0
  44. package/dist/src/document/utils/base.js.map +1 -0
  45. package/dist/src/document/utils/browser.d.ts +18 -0
  46. package/dist/src/document/utils/browser.d.ts.map +1 -0
  47. package/dist/src/document/utils/browser.js +54 -0
  48. package/dist/src/document/utils/browser.js.map +1 -0
  49. package/dist/src/document/utils/crypto.d.ts +11 -0
  50. package/dist/src/document/utils/crypto.d.ts.map +1 -0
  51. package/dist/src/document/utils/crypto.js +80 -0
  52. package/dist/src/document/utils/crypto.js.map +1 -0
  53. package/dist/src/document/utils/document-helpers.d.ts +78 -0
  54. package/dist/src/document/utils/document-helpers.d.ts.map +1 -0
  55. package/dist/src/document/utils/document-helpers.js +411 -0
  56. package/dist/src/document/utils/document-helpers.js.map +1 -0
  57. package/dist/src/document/utils/errors.d.ts +10 -0
  58. package/dist/src/document/utils/errors.d.ts.map +1 -0
  59. package/dist/src/document/utils/errors.js +19 -0
  60. package/dist/src/document/utils/errors.js.map +1 -0
  61. package/dist/{node/src → src}/document/utils/file.d.ts +10 -8
  62. package/dist/src/document/utils/file.d.ts.map +1 -0
  63. package/dist/src/document/utils/file.js +158 -0
  64. package/dist/src/document/utils/file.js.map +1 -0
  65. package/dist/src/document/utils/node.d.ts +18 -0
  66. package/dist/src/document/utils/node.d.ts.map +1 -0
  67. package/dist/src/document/utils/node.js +62 -0
  68. package/dist/src/document/utils/node.js.map +1 -0
  69. package/dist/src/document/utils/validation.d.ts +3 -0
  70. package/dist/src/document/utils/validation.d.ts.map +1 -0
  71. package/dist/src/document/utils/validation.js +23 -0
  72. package/dist/src/document/utils/validation.js.map +1 -0
  73. package/dist/src/document-model/custom/reducers/header.d.ts +3 -0
  74. package/dist/src/document-model/custom/reducers/header.d.ts.map +1 -0
  75. package/dist/src/document-model/custom/reducers/header.js +23 -0
  76. package/dist/src/document-model/custom/reducers/header.js.map +1 -0
  77. package/dist/src/document-model/custom/reducers/module.d.ts +3 -0
  78. package/dist/src/document-model/custom/reducers/module.d.ts.map +1 -0
  79. package/dist/src/document-model/custom/reducers/module.js +41 -0
  80. package/dist/src/document-model/custom/reducers/module.js.map +1 -0
  81. package/dist/src/document-model/custom/reducers/operation-error.d.ts +3 -0
  82. package/dist/src/document-model/custom/reducers/operation-error.d.ts.map +1 -0
  83. package/dist/src/document-model/custom/reducers/operation-error.js +94 -0
  84. package/dist/src/document-model/custom/reducers/operation-error.js.map +1 -0
  85. package/dist/src/document-model/custom/reducers/operation-example.d.ts +3 -0
  86. package/dist/src/document-model/custom/reducers/operation-example.d.ts.map +1 -0
  87. package/dist/src/document-model/custom/reducers/operation-example.js +53 -0
  88. package/dist/src/document-model/custom/reducers/operation-example.js.map +1 -0
  89. package/dist/src/document-model/custom/reducers/operation.d.ts +3 -0
  90. package/dist/src/document-model/custom/reducers/operation.d.ts.map +1 -0
  91. package/dist/src/document-model/custom/reducers/operation.js +125 -0
  92. package/dist/src/document-model/custom/reducers/operation.js.map +1 -0
  93. package/dist/src/document-model/custom/reducers/state.d.ts +3 -0
  94. package/dist/src/document-model/custom/reducers/state.d.ts.map +1 -0
  95. package/dist/src/document-model/custom/reducers/state.js +71 -0
  96. package/dist/src/document-model/custom/reducers/state.js.map +1 -0
  97. package/dist/src/document-model/custom/reducers/versioning.d.ts +8 -0
  98. package/dist/src/document-model/custom/reducers/versioning.d.ts.map +1 -0
  99. package/dist/src/document-model/custom/reducers/versioning.js +23 -0
  100. package/dist/src/document-model/custom/reducers/versioning.js.map +1 -0
  101. package/dist/{browser/src → src}/document-model/custom/utils.d.ts +4 -3
  102. package/dist/src/document-model/custom/utils.d.ts.map +1 -0
  103. package/dist/src/document-model/custom/utils.js +105 -0
  104. package/dist/src/document-model/custom/utils.js.map +1 -0
  105. package/dist/src/document-model/gen/actions.d.ts +16 -0
  106. package/dist/src/document-model/gen/actions.d.ts.map +1 -0
  107. package/dist/src/document-model/gen/actions.js +8 -0
  108. package/dist/src/document-model/gen/actions.js.map +1 -0
  109. package/dist/src/document-model/gen/constants.d.ts +7 -0
  110. package/dist/src/document-model/gen/constants.d.ts.map +1 -0
  111. package/dist/src/document-model/gen/constants.js +34 -0
  112. package/dist/src/document-model/gen/constants.js.map +1 -0
  113. package/dist/src/document-model/gen/creators.d.ts +8 -0
  114. package/dist/src/document-model/gen/creators.d.ts.map +1 -0
  115. package/dist/src/document-model/gen/creators.js +8 -0
  116. package/dist/src/document-model/gen/creators.js.map +1 -0
  117. package/dist/src/document-model/gen/document-model.d.ts +3 -0
  118. package/dist/src/document-model/gen/document-model.d.ts.map +1 -0
  119. package/dist/src/document-model/gen/document-model.js +542 -0
  120. package/dist/src/document-model/gen/document-model.js.map +1 -0
  121. package/dist/src/document-model/gen/header/actions.d.ts +10 -0
  122. package/dist/src/document-model/gen/header/actions.d.ts.map +1 -0
  123. package/dist/src/document-model/gen/header/actions.js +2 -0
  124. package/dist/src/document-model/gen/header/actions.js.map +1 -0
  125. package/dist/{node/src → src}/document-model/gen/header/creators.d.ts +3 -2
  126. package/dist/src/document-model/gen/header/creators.d.ts.map +1 -0
  127. package/dist/src/document-model/gen/header/creators.js +10 -0
  128. package/dist/src/document-model/gen/header/creators.js.map +1 -0
  129. package/dist/src/document-model/gen/header/object.d.ts +13 -0
  130. package/dist/src/document-model/gen/header/object.d.ts.map +1 -0
  131. package/dist/src/document-model/gen/header/object.js +23 -0
  132. package/dist/src/document-model/gen/header/object.js.map +1 -0
  133. package/dist/{node/src → src}/document-model/gen/header/operations.d.ts +3 -2
  134. package/dist/src/document-model/gen/header/operations.d.ts.map +1 -0
  135. package/dist/src/document-model/gen/header/operations.js +2 -0
  136. package/dist/src/document-model/gen/header/operations.js.map +1 -0
  137. package/dist/src/document-model/gen/module/actions.d.ts +9 -0
  138. package/dist/src/document-model/gen/module/actions.d.ts.map +1 -0
  139. package/dist/src/document-model/gen/module/actions.js +2 -0
  140. package/dist/src/document-model/gen/module/actions.js.map +1 -0
  141. package/dist/{node/src → src}/document-model/gen/module/creators.d.ts +3 -2
  142. package/dist/src/document-model/gen/module/creators.d.ts.map +1 -0
  143. package/dist/src/document-model/gen/module/creators.js +9 -0
  144. package/dist/src/document-model/gen/module/creators.js.map +1 -0
  145. package/dist/src/document-model/gen/module/object.d.ts +12 -0
  146. package/dist/src/document-model/gen/module/object.d.ts.map +1 -0
  147. package/dist/src/document-model/gen/module/object.js +20 -0
  148. package/dist/src/document-model/gen/module/object.js.map +1 -0
  149. package/dist/{browser/src → src}/document-model/gen/module/operations.d.ts +3 -2
  150. package/dist/src/document-model/gen/module/operations.d.ts.map +1 -0
  151. package/dist/src/document-model/gen/module/operations.js +2 -0
  152. package/dist/src/document-model/gen/module/operations.js.map +1 -0
  153. package/dist/src/document-model/gen/object.d.ts +29 -0
  154. package/dist/src/document-model/gen/object.d.ts.map +1 -0
  155. package/dist/src/document-model/gen/object.js +46 -0
  156. package/dist/src/document-model/gen/object.js.map +1 -0
  157. package/dist/src/document-model/gen/operation/actions.d.ts +14 -0
  158. package/dist/src/document-model/gen/operation/actions.d.ts.map +1 -0
  159. package/dist/src/document-model/gen/operation/actions.js +2 -0
  160. package/dist/src/document-model/gen/operation/actions.js.map +1 -0
  161. package/dist/{browser/src → src}/document-model/gen/operation/creators.d.ts +3 -2
  162. package/dist/src/document-model/gen/operation/creators.d.ts.map +1 -0
  163. package/dist/src/document-model/gen/operation/creators.js +20 -0
  164. package/dist/src/document-model/gen/operation/creators.js.map +1 -0
  165. package/dist/{node/src → src}/document-model/gen/operation/object.d.ts +7 -5
  166. package/dist/src/document-model/gen/operation/object.d.ts.map +1 -0
  167. package/dist/src/document-model/gen/operation/object.js +35 -0
  168. package/dist/src/document-model/gen/operation/object.js.map +1 -0
  169. package/dist/{node/src → src}/document-model/gen/operation/operations.d.ts +3 -2
  170. package/dist/src/document-model/gen/operation/operations.d.ts.map +1 -0
  171. package/dist/src/document-model/gen/operation/operations.js +2 -0
  172. package/dist/src/document-model/gen/operation/operations.js.map +1 -0
  173. package/dist/src/document-model/gen/operation-error/actions.d.ts +11 -0
  174. package/dist/src/document-model/gen/operation-error/actions.d.ts.map +1 -0
  175. package/dist/src/document-model/gen/operation-error/actions.js +2 -0
  176. package/dist/src/document-model/gen/operation-error/actions.js.map +1 -0
  177. package/dist/{node/src → src}/document-model/gen/operation-error/creators.d.ts +3 -2
  178. package/dist/src/document-model/gen/operation-error/creators.d.ts.map +1 -0
  179. package/dist/src/document-model/gen/operation-error/creators.js +17 -0
  180. package/dist/src/document-model/gen/operation-error/creators.js.map +1 -0
  181. package/dist/{node/src → src}/document-model/gen/operation-error/object.d.ts +7 -5
  182. package/dist/src/document-model/gen/operation-error/object.d.ts.map +1 -0
  183. package/dist/src/document-model/gen/operation-error/object.js +26 -0
  184. package/dist/src/document-model/gen/operation-error/object.js.map +1 -0
  185. package/dist/{browser/src → src}/document-model/gen/operation-error/operations.d.ts +3 -2
  186. package/dist/src/document-model/gen/operation-error/operations.d.ts.map +1 -0
  187. package/dist/src/document-model/gen/operation-error/operations.js +2 -0
  188. package/dist/src/document-model/gen/operation-error/operations.js.map +1 -0
  189. package/dist/src/document-model/gen/operation-example/actions.d.ts +8 -0
  190. package/dist/src/document-model/gen/operation-example/actions.d.ts.map +1 -0
  191. package/dist/src/document-model/gen/operation-example/actions.js +2 -0
  192. package/dist/src/document-model/gen/operation-example/actions.js.map +1 -0
  193. package/dist/{browser/src → src}/document-model/gen/operation-example/creators.d.ts +3 -2
  194. package/dist/src/document-model/gen/operation-example/creators.d.ts.map +1 -0
  195. package/dist/src/document-model/gen/operation-example/creators.js +14 -0
  196. package/dist/src/document-model/gen/operation-example/creators.js.map +1 -0
  197. package/dist/src/document-model/gen/operation-example/object.d.ts +12 -0
  198. package/dist/src/document-model/gen/operation-example/object.d.ts.map +1 -0
  199. package/dist/src/document-model/gen/operation-example/object.js +17 -0
  200. package/dist/src/document-model/gen/operation-example/object.js.map +1 -0
  201. package/dist/{browser/src → src}/document-model/gen/operation-example/operations.d.ts +3 -2
  202. package/dist/src/document-model/gen/operation-example/operations.d.ts.map +1 -0
  203. package/dist/src/document-model/gen/operation-example/operations.js +2 -0
  204. package/dist/src/document-model/gen/operation-example/operations.js.map +1 -0
  205. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  206. package/dist/src/document-model/gen/reducer.d.ts.map +1 -0
  207. package/dist/src/document-model/gen/reducer.js +193 -0
  208. package/dist/src/document-model/gen/reducer.js.map +1 -0
  209. package/dist/{browser/src → src}/document-model/gen/schema/types.d.ts +6 -1
  210. package/dist/src/document-model/gen/schema/types.d.ts.map +1 -0
  211. package/dist/src/document-model/gen/schema/types.js +2 -0
  212. package/dist/src/document-model/gen/schema/types.js.map +1 -0
  213. package/dist/src/document-model/gen/schema/zod.d.ts +454 -0
  214. package/dist/src/document-model/gen/schema/zod.d.ts.map +1 -0
  215. package/dist/src/document-model/gen/schema/zod.js +394 -0
  216. package/dist/src/document-model/gen/schema/zod.js.map +1 -0
  217. package/dist/src/document-model/gen/state/actions.d.ts +10 -0
  218. package/dist/src/document-model/gen/state/actions.d.ts.map +1 -0
  219. package/dist/src/document-model/gen/state/actions.js +2 -0
  220. package/dist/src/document-model/gen/state/actions.js.map +1 -0
  221. package/dist/{browser/src → src}/document-model/gen/state/creators.d.ts +3 -2
  222. package/dist/src/document-model/gen/state/creators.d.ts.map +1 -0
  223. package/dist/src/document-model/gen/state/creators.js +10 -0
  224. package/dist/src/document-model/gen/state/creators.js.map +1 -0
  225. package/dist/src/document-model/gen/state/object.d.ts +13 -0
  226. package/dist/src/document-model/gen/state/object.d.ts.map +1 -0
  227. package/dist/src/document-model/gen/state/object.js +23 -0
  228. package/dist/src/document-model/gen/state/object.js.map +1 -0
  229. package/dist/{browser/src → src}/document-model/gen/state/operations.d.ts +3 -2
  230. package/dist/src/document-model/gen/state/operations.d.ts.map +1 -0
  231. package/dist/src/document-model/gen/state/operations.js +2 -0
  232. package/dist/src/document-model/gen/state/operations.js.map +1 -0
  233. package/dist/src/document-model/gen/types.d.ts +7 -0
  234. package/dist/src/document-model/gen/types.d.ts.map +1 -0
  235. package/dist/src/document-model/gen/types.js +2 -0
  236. package/dist/src/document-model/gen/types.js.map +1 -0
  237. package/dist/src/document-model/gen/utils.d.ts +11 -0
  238. package/dist/src/document-model/gen/utils.d.ts.map +1 -0
  239. package/dist/src/document-model/gen/utils.js +30 -0
  240. package/dist/src/document-model/gen/utils.js.map +1 -0
  241. package/dist/src/document-model/gen/versioning/actions.d.ts +9 -0
  242. package/dist/src/document-model/gen/versioning/actions.d.ts.map +1 -0
  243. package/dist/src/document-model/gen/versioning/actions.js +2 -0
  244. package/dist/src/document-model/gen/versioning/actions.js.map +1 -0
  245. package/dist/{browser/src → src}/document-model/gen/versioning/creators.d.ts +3 -2
  246. package/dist/src/document-model/gen/versioning/creators.d.ts.map +1 -0
  247. package/dist/src/document-model/gen/versioning/creators.js +13 -0
  248. package/dist/src/document-model/gen/versioning/creators.js.map +1 -0
  249. package/dist/src/document-model/gen/versioning/object.d.ts +13 -0
  250. package/dist/src/document-model/gen/versioning/object.d.ts.map +1 -0
  251. package/dist/src/document-model/gen/versioning/object.js +20 -0
  252. package/dist/src/document-model/gen/versioning/object.js.map +1 -0
  253. package/dist/{browser/src → src}/document-model/gen/versioning/operations.d.ts +3 -2
  254. package/dist/src/document-model/gen/versioning/operations.d.ts.map +1 -0
  255. package/dist/src/document-model/gen/versioning/operations.js +2 -0
  256. package/dist/src/document-model/gen/versioning/operations.js.map +1 -0
  257. package/dist/src/document-model/module.d.ts +3 -0
  258. package/dist/src/document-model/module.d.ts.map +1 -0
  259. package/dist/src/document-model/module.js +13 -0
  260. package/dist/src/document-model/module.js.map +1 -0
  261. package/dist/src/document-model/types.d.ts +4 -0
  262. package/dist/src/document-model/types.d.ts.map +1 -0
  263. package/dist/src/document-model/types.js +2 -0
  264. package/dist/src/document-model/types.js.map +1 -0
  265. package/dist/test/document/crypto.test.d.ts +2 -0
  266. package/dist/test/document/crypto.test.d.ts.map +1 -0
  267. package/dist/test/document/crypto.test.js +181 -0
  268. package/dist/test/document/crypto.test.js.map +1 -0
  269. package/dist/test/document/event-vs-command.test.d.ts +2 -0
  270. package/dist/test/document/event-vs-command.test.d.ts.map +1 -0
  271. package/dist/test/document/event-vs-command.test.js +169 -0
  272. package/dist/test/document/event-vs-command.test.js.map +1 -0
  273. package/dist/test/document/local.test.d.ts +2 -0
  274. package/dist/test/document/local.test.d.ts.map +1 -0
  275. package/dist/test/document/local.test.js +248 -0
  276. package/dist/test/document/local.test.js.map +1 -0
  277. package/dist/test/document/object.test.d.ts +2 -0
  278. package/dist/test/document/object.test.d.ts.map +1 -0
  279. package/dist/test/document/object.test.js +13 -0
  280. package/dist/test/document/object.test.js.map +1 -0
  281. package/dist/test/document/operation-id.test.d.ts +2 -0
  282. package/dist/test/document/operation-id.test.d.ts.map +1 -0
  283. package/dist/test/document/operation-id.test.js +159 -0
  284. package/dist/test/document/operation-id.test.js.map +1 -0
  285. package/dist/test/document/prune.test.d.ts +2 -0
  286. package/dist/test/document/prune.test.d.ts.map +1 -0
  287. package/dist/test/document/prune.test.js +177 -0
  288. package/dist/test/document/prune.test.js.map +1 -0
  289. package/dist/test/document/reducer.test.d.ts +2 -0
  290. package/dist/test/document/reducer.test.d.ts.map +1 -0
  291. package/dist/test/document/reducer.test.js +270 -0
  292. package/dist/test/document/reducer.test.js.map +1 -0
  293. package/dist/test/document/skip-operations.test.d.ts +2 -0
  294. package/dist/test/document/skip-operations.test.d.ts.map +1 -0
  295. package/dist/test/document/skip-operations.test.js +442 -0
  296. package/dist/test/document/skip-operations.test.js.map +1 -0
  297. package/dist/test/document/undo-redo.test.d.ts +2 -0
  298. package/dist/test/document/undo-redo.test.d.ts.map +1 -0
  299. package/dist/test/document/undo-redo.test.js +377 -0
  300. package/dist/test/document/undo-redo.test.js.map +1 -0
  301. package/dist/test/document/utils.test.d.ts +2 -0
  302. package/dist/test/document/utils.test.d.ts.map +1 -0
  303. package/dist/test/document/utils.test.js +152 -0
  304. package/dist/test/document/utils.test.js.map +1 -0
  305. package/dist/test/document-helpers/addUndo.test.d.ts +2 -0
  306. package/dist/test/document-helpers/addUndo.test.d.ts.map +1 -0
  307. package/dist/test/document-helpers/addUndo.test.js +120 -0
  308. package/dist/test/document-helpers/addUndo.test.js.map +1 -0
  309. package/dist/test/document-helpers/attachBranch.test.d.ts +2 -0
  310. package/dist/test/document-helpers/attachBranch.test.d.ts.map +1 -0
  311. package/dist/test/document-helpers/attachBranch.test.js +364 -0
  312. package/dist/test/document-helpers/attachBranch.test.js.map +1 -0
  313. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +2 -0
  314. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts.map +1 -0
  315. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +252 -0
  316. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +1 -0
  317. package/dist/test/document-helpers/conflictResolution.test.d.ts +2 -0
  318. package/dist/test/document-helpers/conflictResolution.test.d.ts.map +1 -0
  319. package/dist/test/document-helpers/conflictResolution.test.js +109 -0
  320. package/dist/test/document-helpers/conflictResolution.test.js.map +1 -0
  321. package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts +2 -0
  322. package/dist/test/document-helpers/filterDuplicatedOperations.test.d.ts.map +1 -0
  323. package/dist/test/document-helpers/filterDuplicatedOperations.test.js +126 -0
  324. package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +1 -0
  325. package/dist/test/document-helpers/garbageCollect.test.d.ts +2 -0
  326. package/dist/test/document-helpers/garbageCollect.test.d.ts.map +1 -0
  327. package/dist/test/document-helpers/garbageCollect.test.js +136 -0
  328. package/dist/test/document-helpers/garbageCollect.test.js.map +1 -0
  329. package/dist/test/document-helpers/groupOperationsByScope.test.d.ts +2 -0
  330. package/dist/test/document-helpers/groupOperationsByScope.test.d.ts.map +1 -0
  331. package/dist/test/document-helpers/groupOperationsByScope.test.js +98 -0
  332. package/dist/test/document-helpers/groupOperationsByScope.test.js.map +1 -0
  333. package/dist/test/document-helpers/merge.test.d.ts +2 -0
  334. package/dist/test/document-helpers/merge.test.d.ts.map +1 -0
  335. package/dist/test/document-helpers/merge.test.js +906 -0
  336. package/dist/test/document-helpers/merge.test.js.map +1 -0
  337. package/dist/test/document-helpers/nextSkipNumber.test.d.ts +2 -0
  338. package/dist/test/document-helpers/nextSkipNumber.test.d.ts.map +1 -0
  339. package/dist/test/document-helpers/nextSkipNumber.test.js +135 -0
  340. package/dist/test/document-helpers/nextSkipNumber.test.js.map +1 -0
  341. package/dist/test/document-helpers/prepareOperations.test.d.ts +2 -0
  342. package/dist/test/document-helpers/prepareOperations.test.d.ts.map +1 -0
  343. package/dist/test/document-helpers/prepareOperations.test.js +304 -0
  344. package/dist/test/document-helpers/prepareOperations.test.js.map +1 -0
  345. package/dist/test/document-helpers/removeExistingOperations.test.d.ts +2 -0
  346. package/dist/test/document-helpers/removeExistingOperations.test.d.ts.map +1 -0
  347. package/dist/test/document-helpers/removeExistingOperations.test.js +150 -0
  348. package/dist/test/document-helpers/removeExistingOperations.test.js.map +1 -0
  349. package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts +2 -0
  350. package/dist/test/document-helpers/reshuffleByTimestamp.test.d.ts.map +1 -0
  351. package/dist/test/document-helpers/reshuffleByTimestamp.test.js +148 -0
  352. package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +1 -0
  353. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +2 -0
  354. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts.map +1 -0
  355. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +200 -0
  356. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +1 -0
  357. package/dist/test/document-helpers/skipHeaderOperations.test.d.ts +2 -0
  358. package/dist/test/document-helpers/skipHeaderOperations.test.d.ts.map +1 -0
  359. package/dist/test/document-helpers/skipHeaderOperations.test.js +74 -0
  360. package/dist/test/document-helpers/skipHeaderOperations.test.js.map +1 -0
  361. package/dist/test/document-helpers/sortOperations.test.d.ts +2 -0
  362. package/dist/test/document-helpers/sortOperations.test.d.ts.map +1 -0
  363. package/dist/test/document-helpers/sortOperations.test.js +101 -0
  364. package/dist/test/document-helpers/sortOperations.test.js.map +1 -0
  365. package/dist/test/document-helpers/split.test.d.ts +2 -0
  366. package/dist/test/document-helpers/split.test.d.ts.map +1 -0
  367. package/dist/test/document-helpers/split.test.js +121 -0
  368. package/dist/test/document-helpers/split.test.js.map +1 -0
  369. package/dist/{browser/test → test}/document-helpers/utils.d.ts +2 -1
  370. package/dist/test/document-helpers/utils.d.ts.map +1 -0
  371. package/dist/test/document-helpers/utils.js +22 -0
  372. package/dist/test/document-helpers/utils.js.map +1 -0
  373. package/dist/test/document-model/object.test.d.ts +2 -0
  374. package/dist/test/document-model/object.test.d.ts.map +1 -0
  375. package/dist/test/document-model/object.test.js +243 -0
  376. package/dist/test/document-model/object.test.js.map +1 -0
  377. package/dist/test/document-model/replay.test.d.ts +2 -0
  378. package/dist/test/document-model/replay.test.d.ts.map +1 -0
  379. package/dist/test/document-model/replay.test.js +149 -0
  380. package/dist/test/document-model/replay.test.js.map +1 -0
  381. package/dist/test/document-model/skip-operations.test.d.ts +2 -0
  382. package/dist/test/document-model/skip-operations.test.d.ts.map +1 -0
  383. package/dist/test/document-model/skip-operations.test.js +220 -0
  384. package/dist/test/document-model/skip-operations.test.js.map +1 -0
  385. package/dist/test/document-model/validation.test.d.ts +2 -0
  386. package/dist/test/document-model/validation.test.d.ts.map +1 -0
  387. package/dist/test/document-model/validation.test.js +258 -0
  388. package/dist/test/document-model/validation.test.js.map +1 -0
  389. package/dist/test/document-model/zip.test.d.ts +2 -0
  390. package/dist/test/document-model/zip.test.d.ts.map +1 -0
  391. package/dist/test/document-model/zip.test.js +80 -0
  392. package/dist/test/document-model/zip.test.js.map +1 -0
  393. package/dist/test/helpers.d.ts +31 -0
  394. package/dist/test/helpers.d.ts.map +1 -0
  395. package/dist/test/helpers.js +71 -0
  396. package/dist/test/helpers.js.map +1 -0
  397. package/dist/tsconfig.tsbuildinfo +1 -0
  398. package/dist/vitest.config.d.ts +3 -0
  399. package/dist/vitest.config.d.ts.map +1 -0
  400. package/dist/vitest.config.js +13 -0
  401. package/dist/vitest.config.js.map +1 -0
  402. package/package.json +27 -53
  403. package/dist/browser/cjs/document-model.js +0 -20
  404. package/dist/browser/cjs/document-model.js.map +0 -1
  405. package/dist/browser/cjs/document.js +0 -15
  406. package/dist/browser/cjs/document.js.map +0 -1
  407. package/dist/browser/cjs/index.js +0 -14
  408. package/dist/browser/cjs/index.js.map +0 -1
  409. package/dist/browser/cjs/internal/index-DyKphRZa.js +0 -2215
  410. package/dist/browser/cjs/internal/index-DyKphRZa.js.map +0 -1
  411. package/dist/browser/cjs/internal/index-y9w_m1Lo.js +0 -57
  412. package/dist/browser/cjs/internal/index-y9w_m1Lo.js.map +0 -1
  413. package/dist/browser/cjs/internal/object-Dbc1GbBl.js +0 -2694
  414. package/dist/browser/cjs/internal/object-Dbc1GbBl.js.map +0 -1
  415. package/dist/browser/cjs/package.json +0 -1
  416. package/dist/browser/document-model.d.ts +0 -2
  417. package/dist/browser/document.d.ts +0 -2
  418. package/dist/browser/es/document-model.js +0 -20
  419. package/dist/browser/es/document-model.js.map +0 -1
  420. package/dist/browser/es/document.js +0 -15
  421. package/dist/browser/es/document.js.map +0 -1
  422. package/dist/browser/es/index.js +0 -14
  423. package/dist/browser/es/index.js.map +0 -1
  424. package/dist/browser/es/internal/index-BI16PNmr.js +0 -58
  425. package/dist/browser/es/internal/index-BI16PNmr.js.map +0 -1
  426. package/dist/browser/es/internal/index-CiQX4huJ.js +0 -2216
  427. package/dist/browser/es/internal/index-CiQX4huJ.js.map +0 -1
  428. package/dist/browser/es/internal/object-BTIqCvb-.js +0 -2695
  429. package/dist/browser/es/internal/object-BTIqCvb-.js.map +0 -1
  430. package/dist/browser/es/package.json +0 -1
  431. package/dist/browser/index.d.ts +0 -6
  432. package/dist/browser/src/document/actions/index.d.ts +0 -14
  433. package/dist/browser/src/document/actions/types.d.ts +0 -15
  434. package/dist/browser/src/document/index.d.ts +0 -6
  435. package/dist/browser/src/document/reducer.d.ts +0 -65
  436. package/dist/browser/src/document/schema/index.d.ts +0 -2
  437. package/dist/browser/src/document/signal.d.ts +0 -29
  438. package/dist/browser/src/document/types.d.ts +0 -271
  439. package/dist/browser/src/document/utils/base.d.ts +0 -87
  440. package/dist/browser/src/document/utils/crypto.d.ts +0 -9
  441. package/dist/browser/src/document/utils/document-helpers.d.ts +0 -73
  442. package/dist/browser/src/document/utils/file.d.ts +0 -48
  443. package/dist/browser/src/document/utils/index.d.ts +0 -6
  444. package/dist/browser/src/document/utils/node.d.ts +0 -9
  445. package/dist/browser/src/document/utils/validation.d.ts +0 -2
  446. package/dist/browser/src/document-model/custom/reducers/header.d.ts +0 -2
  447. package/dist/browser/src/document-model/custom/reducers/module.d.ts +0 -2
  448. package/dist/browser/src/document-model/custom/reducers/operation-error.d.ts +0 -2
  449. package/dist/browser/src/document-model/custom/reducers/operation-example.d.ts +0 -2
  450. package/dist/browser/src/document-model/custom/reducers/operation.d.ts +0 -2
  451. package/dist/browser/src/document-model/custom/reducers/state.d.ts +0 -2
  452. package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +0 -2
  453. package/dist/browser/src/document-model/gen/actions.d.ts +0 -15
  454. package/dist/browser/src/document-model/gen/creators.d.ts +0 -7
  455. package/dist/browser/src/document-model/gen/document-model.d.ts +0 -2
  456. package/dist/browser/src/document-model/gen/header/actions.d.ts +0 -9
  457. package/dist/browser/src/document-model/gen/header/creators.d.ts +0 -8
  458. package/dist/browser/src/document-model/gen/header/object.d.ts +0 -12
  459. package/dist/browser/src/document-model/gen/header/operations.d.ts +0 -10
  460. package/dist/browser/src/document-model/gen/index.d.ts +0 -5
  461. package/dist/browser/src/document-model/gen/module/actions.d.ts +0 -8
  462. package/dist/browser/src/document-model/gen/module/creators.d.ts +0 -7
  463. package/dist/browser/src/document-model/gen/module/object.d.ts +0 -11
  464. package/dist/browser/src/document-model/gen/object.d.ts +0 -28
  465. package/dist/browser/src/document-model/gen/operation/actions.d.ts +0 -13
  466. package/dist/browser/src/document-model/gen/operation/object.d.ts +0 -16
  467. package/dist/browser/src/document-model/gen/operation/operations.d.ts +0 -14
  468. package/dist/browser/src/document-model/gen/operation-error/actions.d.ts +0 -10
  469. package/dist/browser/src/document-model/gen/operation-error/creators.d.ts +0 -9
  470. package/dist/browser/src/document-model/gen/operation-error/object.d.ts +0 -13
  471. package/dist/browser/src/document-model/gen/operation-example/actions.d.ts +0 -7
  472. package/dist/browser/src/document-model/gen/operation-example/object.d.ts +0 -10
  473. package/dist/browser/src/document-model/gen/reducer.d.ts +0 -5
  474. package/dist/browser/src/document-model/gen/schema/index.d.ts +0 -2
  475. package/dist/browser/src/document-model/gen/schema/zod.d.ts +0 -453
  476. package/dist/browser/src/document-model/gen/state/actions.d.ts +0 -9
  477. package/dist/browser/src/document-model/gen/state/object.d.ts +0 -12
  478. package/dist/browser/src/document-model/gen/types.d.ts +0 -8
  479. package/dist/browser/src/document-model/gen/utils.d.ts +0 -6
  480. package/dist/browser/src/document-model/gen/versioning/actions.d.ts +0 -8
  481. package/dist/browser/src/document-model/gen/versioning/object.d.ts +0 -11
  482. package/dist/browser/src/document-model/index.d.ts +0 -76
  483. package/dist/browser/src/index.d.ts +0 -24
  484. package/dist/browser/test/document/crypto.test.d.ts +0 -1
  485. package/dist/browser/test/document/event-vs-command.test.d.ts +0 -1
  486. package/dist/browser/test/document/local.test.d.ts +0 -1
  487. package/dist/browser/test/document/object.test.d.ts +0 -1
  488. package/dist/browser/test/document/operation-id.test.d.ts +0 -1
  489. package/dist/browser/test/document/prune.test.d.ts +0 -1
  490. package/dist/browser/test/document/reducer.test.d.ts +0 -1
  491. package/dist/browser/test/document/skip-operations.test.d.ts +0 -1
  492. package/dist/browser/test/document/undo-redo.test.d.ts +0 -1
  493. package/dist/browser/test/document/utils.test.d.ts +0 -1
  494. package/dist/browser/test/document-helpers/addUndo.test.d.ts +0 -1
  495. package/dist/browser/test/document-helpers/attachBranch.test.d.ts +0 -1
  496. package/dist/browser/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
  497. package/dist/browser/test/document-helpers/conflictResolution.test.d.ts +0 -1
  498. package/dist/browser/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
  499. package/dist/browser/test/document-helpers/garbageCollect.test.d.ts +0 -1
  500. package/dist/browser/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
  501. package/dist/browser/test/document-helpers/merge.test.d.ts +0 -1
  502. package/dist/browser/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
  503. package/dist/browser/test/document-helpers/prepareOperations.test.d.ts +0 -1
  504. package/dist/browser/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
  505. package/dist/browser/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
  506. package/dist/browser/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
  507. package/dist/browser/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
  508. package/dist/browser/test/document-helpers/sortOperations.test.d.ts +0 -1
  509. package/dist/browser/test/document-helpers/split.test.d.ts +0 -1
  510. package/dist/browser/test/document-model/object.test.d.ts +0 -1
  511. package/dist/browser/test/document-model/replay.test.d.ts +0 -1
  512. package/dist/browser/test/document-model/skip-operations.test.d.ts +0 -1
  513. package/dist/browser/test/document-model/validation.test.d.ts +0 -1
  514. package/dist/browser/test/document-model/zip.test.d.ts +0 -1
  515. package/dist/browser/test/helpers.d.ts +0 -39
  516. package/dist/browser/vite.config.d.ts +0 -2
  517. package/dist/browser/vitest.config.d.ts +0 -2
  518. package/dist/node/cjs/document-model.js +0 -24
  519. package/dist/node/cjs/document-model.js.map +0 -1
  520. package/dist/node/cjs/document.js +0 -15
  521. package/dist/node/cjs/document.js.map +0 -1
  522. package/dist/node/cjs/index.js +0 -14
  523. package/dist/node/cjs/index.js.map +0 -1
  524. package/dist/node/cjs/internal/index-CLCVBs4I.js +0 -57
  525. package/dist/node/cjs/internal/index-CLCVBs4I.js.map +0 -1
  526. package/dist/node/cjs/internal/index-Cp37sm40.js +0 -2219
  527. package/dist/node/cjs/internal/index-Cp37sm40.js.map +0 -1
  528. package/dist/node/cjs/internal/object-ByNZ3G_j.js +0 -2480
  529. package/dist/node/cjs/internal/object-ByNZ3G_j.js.map +0 -1
  530. package/dist/node/cjs/package.json +0 -1
  531. package/dist/node/document-model.d.ts +0 -2
  532. package/dist/node/document.d.ts +0 -2
  533. package/dist/node/es/document-model.js +0 -24
  534. package/dist/node/es/document-model.js.map +0 -1
  535. package/dist/node/es/document.js +0 -15
  536. package/dist/node/es/document.js.map +0 -1
  537. package/dist/node/es/index.js +0 -14
  538. package/dist/node/es/index.js.map +0 -1
  539. package/dist/node/es/internal/index-BXfMlE4L.js +0 -58
  540. package/dist/node/es/internal/index-BXfMlE4L.js.map +0 -1
  541. package/dist/node/es/internal/index-ppDSDiFU.js +0 -2220
  542. package/dist/node/es/internal/index-ppDSDiFU.js.map +0 -1
  543. package/dist/node/es/internal/object-C8sca9DR.js +0 -2481
  544. package/dist/node/es/internal/object-C8sca9DR.js.map +0 -1
  545. package/dist/node/es/package.json +0 -1
  546. package/dist/node/index.d.ts +0 -6
  547. package/dist/node/src/document/actions/index.d.ts +0 -14
  548. package/dist/node/src/document/actions/types.d.ts +0 -15
  549. package/dist/node/src/document/index.d.ts +0 -6
  550. package/dist/node/src/document/reducer.d.ts +0 -65
  551. package/dist/node/src/document/schema/index.d.ts +0 -2
  552. package/dist/node/src/document/schema/types.d.ts +0 -176
  553. package/dist/node/src/document/schema/zod.d.ts +0 -116
  554. package/dist/node/src/document/types.d.ts +0 -271
  555. package/dist/node/src/document/utils/base.d.ts +0 -87
  556. package/dist/node/src/document/utils/crypto.d.ts +0 -9
  557. package/dist/node/src/document/utils/document-helpers.d.ts +0 -73
  558. package/dist/node/src/document/utils/index.d.ts +0 -6
  559. package/dist/node/src/document/utils/node.d.ts +0 -9
  560. package/dist/node/src/document/utils/validation.d.ts +0 -2
  561. package/dist/node/src/document-model/custom/reducers/header.d.ts +0 -2
  562. package/dist/node/src/document-model/custom/reducers/module.d.ts +0 -2
  563. package/dist/node/src/document-model/custom/reducers/operation-error.d.ts +0 -2
  564. package/dist/node/src/document-model/custom/reducers/operation-example.d.ts +0 -2
  565. package/dist/node/src/document-model/custom/reducers/operation.d.ts +0 -2
  566. package/dist/node/src/document-model/custom/reducers/state.d.ts +0 -2
  567. package/dist/node/src/document-model/custom/reducers/versioning.d.ts +0 -2
  568. package/dist/node/src/document-model/custom/utils.d.ts +0 -7
  569. package/dist/node/src/document-model/gen/actions.d.ts +0 -15
  570. package/dist/node/src/document-model/gen/creators.d.ts +0 -7
  571. package/dist/node/src/document-model/gen/document-model.d.ts +0 -2
  572. package/dist/node/src/document-model/gen/header/actions.d.ts +0 -9
  573. package/dist/node/src/document-model/gen/header/object.d.ts +0 -12
  574. package/dist/node/src/document-model/gen/index.d.ts +0 -5
  575. package/dist/node/src/document-model/gen/module/actions.d.ts +0 -8
  576. package/dist/node/src/document-model/gen/module/object.d.ts +0 -11
  577. package/dist/node/src/document-model/gen/module/operations.d.ts +0 -9
  578. package/dist/node/src/document-model/gen/object.d.ts +0 -28
  579. package/dist/node/src/document-model/gen/operation/actions.d.ts +0 -13
  580. package/dist/node/src/document-model/gen/operation/creators.d.ts +0 -12
  581. package/dist/node/src/document-model/gen/operation-error/actions.d.ts +0 -10
  582. package/dist/node/src/document-model/gen/operation-error/operations.d.ts +0 -11
  583. package/dist/node/src/document-model/gen/operation-example/actions.d.ts +0 -7
  584. package/dist/node/src/document-model/gen/operation-example/creators.d.ts +0 -6
  585. package/dist/node/src/document-model/gen/operation-example/object.d.ts +0 -10
  586. package/dist/node/src/document-model/gen/operation-example/operations.d.ts +0 -8
  587. package/dist/node/src/document-model/gen/reducer.d.ts +0 -5
  588. package/dist/node/src/document-model/gen/schema/index.d.ts +0 -2
  589. package/dist/node/src/document-model/gen/schema/types.d.ts +0 -453
  590. package/dist/node/src/document-model/gen/schema/zod.d.ts +0 -453
  591. package/dist/node/src/document-model/gen/state/actions.d.ts +0 -9
  592. package/dist/node/src/document-model/gen/state/creators.d.ts +0 -8
  593. package/dist/node/src/document-model/gen/state/object.d.ts +0 -12
  594. package/dist/node/src/document-model/gen/state/operations.d.ts +0 -10
  595. package/dist/node/src/document-model/gen/types.d.ts +0 -8
  596. package/dist/node/src/document-model/gen/utils.d.ts +0 -6
  597. package/dist/node/src/document-model/gen/versioning/actions.d.ts +0 -8
  598. package/dist/node/src/document-model/gen/versioning/creators.d.ts +0 -7
  599. package/dist/node/src/document-model/gen/versioning/object.d.ts +0 -11
  600. package/dist/node/src/document-model/gen/versioning/operations.d.ts +0 -9
  601. package/dist/node/src/document-model/index.d.ts +0 -76
  602. package/dist/node/src/index.d.ts +0 -24
  603. package/dist/node/test/document/crypto.test.d.ts +0 -1
  604. package/dist/node/test/document/event-vs-command.test.d.ts +0 -1
  605. package/dist/node/test/document/local.test.d.ts +0 -1
  606. package/dist/node/test/document/object.test.d.ts +0 -1
  607. package/dist/node/test/document/operation-id.test.d.ts +0 -1
  608. package/dist/node/test/document/prune.test.d.ts +0 -1
  609. package/dist/node/test/document/reducer.test.d.ts +0 -1
  610. package/dist/node/test/document/skip-operations.test.d.ts +0 -1
  611. package/dist/node/test/document/undo-redo.test.d.ts +0 -1
  612. package/dist/node/test/document/utils.test.d.ts +0 -1
  613. package/dist/node/test/document-helpers/addUndo.test.d.ts +0 -1
  614. package/dist/node/test/document-helpers/attachBranch.test.d.ts +0 -1
  615. package/dist/node/test/document-helpers/checkCleanedOperationsIntegrity.test.d.ts +0 -1
  616. package/dist/node/test/document-helpers/conflictResolution.test.d.ts +0 -1
  617. package/dist/node/test/document-helpers/filterDuplicatedOperations.test.d.ts +0 -1
  618. package/dist/node/test/document-helpers/garbageCollect.test.d.ts +0 -1
  619. package/dist/node/test/document-helpers/groupOperationsByScope.test.d.ts +0 -1
  620. package/dist/node/test/document-helpers/merge.test.d.ts +0 -1
  621. package/dist/node/test/document-helpers/nextSkipNumber.test.d.ts +0 -1
  622. package/dist/node/test/document-helpers/prepareOperations.test.d.ts +0 -1
  623. package/dist/node/test/document-helpers/removeExistingOperations.test.d.ts +0 -1
  624. package/dist/node/test/document-helpers/reshuffleByTimestamp.test.d.ts +0 -1
  625. package/dist/node/test/document-helpers/reshuffleByTimestampAndIndex.test.d.ts +0 -1
  626. package/dist/node/test/document-helpers/skipHeaderOperations.test.d.ts +0 -1
  627. package/dist/node/test/document-helpers/sortOperations.test.d.ts +0 -1
  628. package/dist/node/test/document-helpers/split.test.d.ts +0 -1
  629. package/dist/node/test/document-helpers/utils.d.ts +0 -7
  630. package/dist/node/test/document-model/object.test.d.ts +0 -1
  631. package/dist/node/test/document-model/replay.test.d.ts +0 -1
  632. package/dist/node/test/document-model/skip-operations.test.d.ts +0 -1
  633. package/dist/node/test/document-model/validation.test.d.ts +0 -1
  634. package/dist/node/test/document-model/zip.test.d.ts +0 -1
  635. package/dist/node/test/helpers.d.ts +0 -39
  636. package/dist/node/vite.config.d.ts +0 -2
  637. package/dist/node/vitest.config.d.ts +0 -2
@@ -1,2480 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- const mutative = require("mutative");
6
- const zod$1 = require("zod");
7
- const crypto$1 = require("crypto");
8
- const fs = require("fs");
9
- const https = require("https");
10
- const path = require("path");
11
- const JSZip = require("jszip");
12
- const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
13
- const definedNonNullAnySchema = zod$1.z.any().refine((v) => isDefinedNonNullAny(v));
14
- const Load_StateSchema = zod$1.z.enum(["LOAD_STATE"]);
15
- const PruneSchema = zod$1.z.enum(["PRUNE"]);
16
- const RedoSchema = zod$1.z.enum(["REDO"]);
17
- const Set_NameSchema = zod$1.z.enum(["SET_NAME"]);
18
- const UndoSchema = zod$1.z.enum(["UNDO"]);
19
- function ActionSchema() {
20
- return zod$1.z.object({
21
- __typename: zod$1.z.literal("Action").optional(),
22
- type: zod$1.z.string()
23
- });
24
- }
25
- function OperationScopeSchema() {
26
- return zod$1.z.literal("global").or(zod$1.z.literal("local"));
27
- }
28
- function BaseActionSchema() {
29
- return zod$1.z.union([
30
- LoadStateActionSchema(),
31
- PruneActionSchema(),
32
- RedoActionSchema(),
33
- SetNameActionSchema(),
34
- UndoActionSchema()
35
- ]);
36
- }
37
- function DocumentFileSchema() {
38
- return zod$1.z.object({
39
- __typename: zod$1.z.literal("DocumentFile").optional(),
40
- data: zod$1.z.string(),
41
- extension: zod$1.z.string().nullable(),
42
- fileName: zod$1.z.string().nullable(),
43
- mimeType: zod$1.z.string()
44
- });
45
- }
46
- function LoadStateActionSchema() {
47
- return zod$1.z.object({
48
- input: zod$1.z.lazy(() => LoadStateActionInputSchema()),
49
- type: Load_StateSchema,
50
- scope: OperationScopeSchema()
51
- });
52
- }
53
- function LoadStateActionInputSchema() {
54
- return zod$1.z.object({
55
- operations: zod$1.z.number(),
56
- state: zod$1.z.lazy(() => LoadStateActionStateInputSchema())
57
- });
58
- }
59
- function LoadStateActionStateInputSchema() {
60
- return zod$1.z.object({
61
- data: zod$1.z.unknown().nullish(),
62
- name: zod$1.z.string()
63
- });
64
- }
65
- function OperationSchema() {
66
- return zod$1.z.object({
67
- __typename: zod$1.z.literal("Operation").optional(),
68
- hash: zod$1.z.string(),
69
- index: zod$1.z.number(),
70
- timestamp: zod$1.z.string().datetime(),
71
- type: zod$1.z.string()
72
- });
73
- }
74
- function PruneActionSchema() {
75
- return zod$1.z.object({
76
- input: zod$1.z.lazy(() => PruneActionInputSchema()),
77
- type: PruneSchema,
78
- scope: OperationScopeSchema()
79
- });
80
- }
81
- function PruneActionInputSchema() {
82
- return zod$1.z.object({
83
- end: zod$1.z.number().nullish(),
84
- start: zod$1.z.number().nullish()
85
- });
86
- }
87
- const RedoActionInputSchema = zod$1.z.number;
88
- function RedoActionSchema() {
89
- return zod$1.z.object({
90
- input: RedoActionInputSchema(),
91
- type: RedoSchema,
92
- scope: OperationScopeSchema()
93
- });
94
- }
95
- const SetNameActionInputSchema = zod$1.z.string;
96
- function SetNameActionSchema() {
97
- return zod$1.z.object({
98
- input: SetNameActionInputSchema(),
99
- type: Set_NameSchema,
100
- scope: zod$1.z.literal("global")
101
- });
102
- }
103
- function SetNameOperationSchema() {
104
- return zod$1.z.object({
105
- __typename: zod$1.z.literal("SetNameOperation").optional(),
106
- hash: zod$1.z.string(),
107
- index: zod$1.z.number(),
108
- input: zod$1.z.string(),
109
- timestamp: zod$1.z.string().datetime(),
110
- type: zod$1.z.string()
111
- });
112
- }
113
- const UndoActionInputSchema = zod$1.z.number;
114
- function UndoActionSchema() {
115
- return zod$1.z.object({
116
- input: UndoActionInputSchema(),
117
- type: UndoSchema,
118
- scope: OperationScopeSchema()
119
- });
120
- }
121
- const zod = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
122
- __proto__: null,
123
- ActionSchema,
124
- BaseActionSchema,
125
- DocumentFileSchema,
126
- LoadStateActionInputSchema,
127
- LoadStateActionSchema,
128
- LoadStateActionStateInputSchema,
129
- Load_StateSchema,
130
- OperationSchema,
131
- OperationScopeSchema,
132
- PruneActionInputSchema,
133
- PruneActionSchema,
134
- PruneSchema,
135
- RedoActionInputSchema,
136
- RedoActionSchema,
137
- RedoSchema,
138
- SetNameActionInputSchema,
139
- SetNameActionSchema,
140
- SetNameOperationSchema,
141
- Set_NameSchema,
142
- UndoActionInputSchema,
143
- UndoActionSchema,
144
- UndoSchema,
145
- definedNonNullAnySchema,
146
- isDefinedNonNullAny
147
- }, Symbol.toStringTag, { value: "Module" }));
148
- function getDefaultExportFromCjs(x) {
149
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
150
- }
151
- var safeStableStringify = { exports: {} };
152
- (function(module2, exports2) {
153
- const { hasOwnProperty } = Object.prototype;
154
- const stringify = configure();
155
- stringify.configure = configure;
156
- stringify.stringify = stringify;
157
- stringify.default = stringify;
158
- exports2.stringify = stringify;
159
- exports2.configure = configure;
160
- module2.exports = stringify;
161
- const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
162
- function strEscape(str) {
163
- if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
164
- return `"${str}"`;
165
- }
166
- return JSON.stringify(str);
167
- }
168
- function sort(array, comparator) {
169
- if (array.length > 200 || comparator) {
170
- return array.sort(comparator);
171
- }
172
- for (let i = 1; i < array.length; i++) {
173
- const currentValue = array[i];
174
- let position = i;
175
- while (position !== 0 && array[position - 1] > currentValue) {
176
- array[position] = array[position - 1];
177
- position--;
178
- }
179
- array[position] = currentValue;
180
- }
181
- return array;
182
- }
183
- const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
184
- Object.getPrototypeOf(
185
- Object.getPrototypeOf(
186
- new Int8Array()
187
- )
188
- ),
189
- Symbol.toStringTag
190
- ).get;
191
- function isTypedArrayWithEntries(value) {
192
- return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
193
- }
194
- function stringifyTypedArray(array, separator, maximumBreadth) {
195
- if (array.length < maximumBreadth) {
196
- maximumBreadth = array.length;
197
- }
198
- const whitespace = separator === "," ? "" : " ";
199
- let res = `"0":${whitespace}${array[0]}`;
200
- for (let i = 1; i < maximumBreadth; i++) {
201
- res += `${separator}"${i}":${whitespace}${array[i]}`;
202
- }
203
- return res;
204
- }
205
- function getCircularValueOption(options) {
206
- if (hasOwnProperty.call(options, "circularValue")) {
207
- const circularValue = options.circularValue;
208
- if (typeof circularValue === "string") {
209
- return `"${circularValue}"`;
210
- }
211
- if (circularValue == null) {
212
- return circularValue;
213
- }
214
- if (circularValue === Error || circularValue === TypeError) {
215
- return {
216
- toString() {
217
- throw new TypeError("Converting circular structure to JSON");
218
- }
219
- };
220
- }
221
- throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
222
- }
223
- return '"[Circular]"';
224
- }
225
- function getDeterministicOption(options) {
226
- let value;
227
- if (hasOwnProperty.call(options, "deterministic")) {
228
- value = options.deterministic;
229
- if (typeof value !== "boolean" && typeof value !== "function") {
230
- throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
231
- }
232
- }
233
- return value === void 0 ? true : value;
234
- }
235
- function getBooleanOption(options, key) {
236
- let value;
237
- if (hasOwnProperty.call(options, key)) {
238
- value = options[key];
239
- if (typeof value !== "boolean") {
240
- throw new TypeError(`The "${key}" argument must be of type boolean`);
241
- }
242
- }
243
- return value === void 0 ? true : value;
244
- }
245
- function getPositiveIntegerOption(options, key) {
246
- let value;
247
- if (hasOwnProperty.call(options, key)) {
248
- value = options[key];
249
- if (typeof value !== "number") {
250
- throw new TypeError(`The "${key}" argument must be of type number`);
251
- }
252
- if (!Number.isInteger(value)) {
253
- throw new TypeError(`The "${key}" argument must be an integer`);
254
- }
255
- if (value < 1) {
256
- throw new RangeError(`The "${key}" argument must be >= 1`);
257
- }
258
- }
259
- return value === void 0 ? Infinity : value;
260
- }
261
- function getItemCount(number) {
262
- if (number === 1) {
263
- return "1 item";
264
- }
265
- return `${number} items`;
266
- }
267
- function getUniqueReplacerSet(replacerArray) {
268
- const replacerSet = /* @__PURE__ */ new Set();
269
- for (const value of replacerArray) {
270
- if (typeof value === "string" || typeof value === "number") {
271
- replacerSet.add(String(value));
272
- }
273
- }
274
- return replacerSet;
275
- }
276
- function getStrictOption(options) {
277
- if (hasOwnProperty.call(options, "strict")) {
278
- const value = options.strict;
279
- if (typeof value !== "boolean") {
280
- throw new TypeError('The "strict" argument must be of type boolean');
281
- }
282
- if (value) {
283
- return (value2) => {
284
- let message = `Object can not safely be stringified. Received type ${typeof value2}`;
285
- if (typeof value2 !== "function") message += ` (${value2.toString()})`;
286
- throw new Error(message);
287
- };
288
- }
289
- }
290
- }
291
- function configure(options) {
292
- options = { ...options };
293
- const fail = getStrictOption(options);
294
- if (fail) {
295
- if (options.bigint === void 0) {
296
- options.bigint = false;
297
- }
298
- if (!("circularValue" in options)) {
299
- options.circularValue = Error;
300
- }
301
- }
302
- const circularValue = getCircularValueOption(options);
303
- const bigint = getBooleanOption(options, "bigint");
304
- const deterministic = getDeterministicOption(options);
305
- const comparator = typeof deterministic === "function" ? deterministic : void 0;
306
- const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
307
- const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
308
- function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
309
- let value = parent[key];
310
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
311
- value = value.toJSON(key);
312
- }
313
- value = replacer.call(parent, key, value);
314
- switch (typeof value) {
315
- case "string":
316
- return strEscape(value);
317
- case "object": {
318
- if (value === null) {
319
- return "null";
320
- }
321
- if (stack.indexOf(value) !== -1) {
322
- return circularValue;
323
- }
324
- let res = "";
325
- let join = ",";
326
- const originalIndentation = indentation;
327
- if (Array.isArray(value)) {
328
- if (value.length === 0) {
329
- return "[]";
330
- }
331
- if (maximumDepth < stack.length + 1) {
332
- return '"[Array]"';
333
- }
334
- stack.push(value);
335
- if (spacer !== "") {
336
- indentation += spacer;
337
- res += `
338
- ${indentation}`;
339
- join = `,
340
- ${indentation}`;
341
- }
342
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
343
- let i = 0;
344
- for (; i < maximumValuesToStringify - 1; i++) {
345
- const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
346
- res += tmp2 !== void 0 ? tmp2 : "null";
347
- res += join;
348
- }
349
- const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
350
- res += tmp !== void 0 ? tmp : "null";
351
- if (value.length - 1 > maximumBreadth) {
352
- const removedKeys = value.length - maximumBreadth - 1;
353
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
354
- }
355
- if (spacer !== "") {
356
- res += `
357
- ${originalIndentation}`;
358
- }
359
- stack.pop();
360
- return `[${res}]`;
361
- }
362
- let keys = Object.keys(value);
363
- const keyLength = keys.length;
364
- if (keyLength === 0) {
365
- return "{}";
366
- }
367
- if (maximumDepth < stack.length + 1) {
368
- return '"[Object]"';
369
- }
370
- let whitespace = "";
371
- let separator = "";
372
- if (spacer !== "") {
373
- indentation += spacer;
374
- join = `,
375
- ${indentation}`;
376
- whitespace = " ";
377
- }
378
- const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
379
- if (deterministic && !isTypedArrayWithEntries(value)) {
380
- keys = sort(keys, comparator);
381
- }
382
- stack.push(value);
383
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
384
- const key2 = keys[i];
385
- const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
386
- if (tmp !== void 0) {
387
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
388
- separator = join;
389
- }
390
- }
391
- if (keyLength > maximumBreadth) {
392
- const removedKeys = keyLength - maximumBreadth;
393
- res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
394
- separator = join;
395
- }
396
- if (spacer !== "" && separator.length > 1) {
397
- res = `
398
- ${indentation}${res}
399
- ${originalIndentation}`;
400
- }
401
- stack.pop();
402
- return `{${res}}`;
403
- }
404
- case "number":
405
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
406
- case "boolean":
407
- return value === true ? "true" : "false";
408
- case "undefined":
409
- return void 0;
410
- case "bigint":
411
- if (bigint) {
412
- return String(value);
413
- }
414
- default:
415
- return fail ? fail(value) : void 0;
416
- }
417
- }
418
- function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
419
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
420
- value = value.toJSON(key);
421
- }
422
- switch (typeof value) {
423
- case "string":
424
- return strEscape(value);
425
- case "object": {
426
- if (value === null) {
427
- return "null";
428
- }
429
- if (stack.indexOf(value) !== -1) {
430
- return circularValue;
431
- }
432
- const originalIndentation = indentation;
433
- let res = "";
434
- let join = ",";
435
- if (Array.isArray(value)) {
436
- if (value.length === 0) {
437
- return "[]";
438
- }
439
- if (maximumDepth < stack.length + 1) {
440
- return '"[Array]"';
441
- }
442
- stack.push(value);
443
- if (spacer !== "") {
444
- indentation += spacer;
445
- res += `
446
- ${indentation}`;
447
- join = `,
448
- ${indentation}`;
449
- }
450
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
451
- let i = 0;
452
- for (; i < maximumValuesToStringify - 1; i++) {
453
- const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
454
- res += tmp2 !== void 0 ? tmp2 : "null";
455
- res += join;
456
- }
457
- const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
458
- res += tmp !== void 0 ? tmp : "null";
459
- if (value.length - 1 > maximumBreadth) {
460
- const removedKeys = value.length - maximumBreadth - 1;
461
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
462
- }
463
- if (spacer !== "") {
464
- res += `
465
- ${originalIndentation}`;
466
- }
467
- stack.pop();
468
- return `[${res}]`;
469
- }
470
- stack.push(value);
471
- let whitespace = "";
472
- if (spacer !== "") {
473
- indentation += spacer;
474
- join = `,
475
- ${indentation}`;
476
- whitespace = " ";
477
- }
478
- let separator = "";
479
- for (const key2 of replacer) {
480
- const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
481
- if (tmp !== void 0) {
482
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
483
- separator = join;
484
- }
485
- }
486
- if (spacer !== "" && separator.length > 1) {
487
- res = `
488
- ${indentation}${res}
489
- ${originalIndentation}`;
490
- }
491
- stack.pop();
492
- return `{${res}}`;
493
- }
494
- case "number":
495
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
496
- case "boolean":
497
- return value === true ? "true" : "false";
498
- case "undefined":
499
- return void 0;
500
- case "bigint":
501
- if (bigint) {
502
- return String(value);
503
- }
504
- default:
505
- return fail ? fail(value) : void 0;
506
- }
507
- }
508
- function stringifyIndent(key, value, stack, spacer, indentation) {
509
- switch (typeof value) {
510
- case "string":
511
- return strEscape(value);
512
- case "object": {
513
- if (value === null) {
514
- return "null";
515
- }
516
- if (typeof value.toJSON === "function") {
517
- value = value.toJSON(key);
518
- if (typeof value !== "object") {
519
- return stringifyIndent(key, value, stack, spacer, indentation);
520
- }
521
- if (value === null) {
522
- return "null";
523
- }
524
- }
525
- if (stack.indexOf(value) !== -1) {
526
- return circularValue;
527
- }
528
- const originalIndentation = indentation;
529
- if (Array.isArray(value)) {
530
- if (value.length === 0) {
531
- return "[]";
532
- }
533
- if (maximumDepth < stack.length + 1) {
534
- return '"[Array]"';
535
- }
536
- stack.push(value);
537
- indentation += spacer;
538
- let res2 = `
539
- ${indentation}`;
540
- const join2 = `,
541
- ${indentation}`;
542
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
543
- let i = 0;
544
- for (; i < maximumValuesToStringify - 1; i++) {
545
- const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
546
- res2 += tmp2 !== void 0 ? tmp2 : "null";
547
- res2 += join2;
548
- }
549
- const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
550
- res2 += tmp !== void 0 ? tmp : "null";
551
- if (value.length - 1 > maximumBreadth) {
552
- const removedKeys = value.length - maximumBreadth - 1;
553
- res2 += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
554
- }
555
- res2 += `
556
- ${originalIndentation}`;
557
- stack.pop();
558
- return `[${res2}]`;
559
- }
560
- let keys = Object.keys(value);
561
- const keyLength = keys.length;
562
- if (keyLength === 0) {
563
- return "{}";
564
- }
565
- if (maximumDepth < stack.length + 1) {
566
- return '"[Object]"';
567
- }
568
- indentation += spacer;
569
- const join = `,
570
- ${indentation}`;
571
- let res = "";
572
- let separator = "";
573
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
574
- if (isTypedArrayWithEntries(value)) {
575
- res += stringifyTypedArray(value, join, maximumBreadth);
576
- keys = keys.slice(value.length);
577
- maximumPropertiesToStringify -= value.length;
578
- separator = join;
579
- }
580
- if (deterministic) {
581
- keys = sort(keys, comparator);
582
- }
583
- stack.push(value);
584
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
585
- const key2 = keys[i];
586
- const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
587
- if (tmp !== void 0) {
588
- res += `${separator}${strEscape(key2)}: ${tmp}`;
589
- separator = join;
590
- }
591
- }
592
- if (keyLength > maximumBreadth) {
593
- const removedKeys = keyLength - maximumBreadth;
594
- res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
595
- separator = join;
596
- }
597
- if (separator !== "") {
598
- res = `
599
- ${indentation}${res}
600
- ${originalIndentation}`;
601
- }
602
- stack.pop();
603
- return `{${res}}`;
604
- }
605
- case "number":
606
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
607
- case "boolean":
608
- return value === true ? "true" : "false";
609
- case "undefined":
610
- return void 0;
611
- case "bigint":
612
- if (bigint) {
613
- return String(value);
614
- }
615
- default:
616
- return fail ? fail(value) : void 0;
617
- }
618
- }
619
- function stringifySimple(key, value, stack) {
620
- switch (typeof value) {
621
- case "string":
622
- return strEscape(value);
623
- case "object": {
624
- if (value === null) {
625
- return "null";
626
- }
627
- if (typeof value.toJSON === "function") {
628
- value = value.toJSON(key);
629
- if (typeof value !== "object") {
630
- return stringifySimple(key, value, stack);
631
- }
632
- if (value === null) {
633
- return "null";
634
- }
635
- }
636
- if (stack.indexOf(value) !== -1) {
637
- return circularValue;
638
- }
639
- let res = "";
640
- const hasLength = value.length !== void 0;
641
- if (hasLength && Array.isArray(value)) {
642
- if (value.length === 0) {
643
- return "[]";
644
- }
645
- if (maximumDepth < stack.length + 1) {
646
- return '"[Array]"';
647
- }
648
- stack.push(value);
649
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
650
- let i = 0;
651
- for (; i < maximumValuesToStringify - 1; i++) {
652
- const tmp2 = stringifySimple(String(i), value[i], stack);
653
- res += tmp2 !== void 0 ? tmp2 : "null";
654
- res += ",";
655
- }
656
- const tmp = stringifySimple(String(i), value[i], stack);
657
- res += tmp !== void 0 ? tmp : "null";
658
- if (value.length - 1 > maximumBreadth) {
659
- const removedKeys = value.length - maximumBreadth - 1;
660
- res += `,"... ${getItemCount(removedKeys)} not stringified"`;
661
- }
662
- stack.pop();
663
- return `[${res}]`;
664
- }
665
- let keys = Object.keys(value);
666
- const keyLength = keys.length;
667
- if (keyLength === 0) {
668
- return "{}";
669
- }
670
- if (maximumDepth < stack.length + 1) {
671
- return '"[Object]"';
672
- }
673
- let separator = "";
674
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
675
- if (hasLength && isTypedArrayWithEntries(value)) {
676
- res += stringifyTypedArray(value, ",", maximumBreadth);
677
- keys = keys.slice(value.length);
678
- maximumPropertiesToStringify -= value.length;
679
- separator = ",";
680
- }
681
- if (deterministic) {
682
- keys = sort(keys, comparator);
683
- }
684
- stack.push(value);
685
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
686
- const key2 = keys[i];
687
- const tmp = stringifySimple(key2, value[key2], stack);
688
- if (tmp !== void 0) {
689
- res += `${separator}${strEscape(key2)}:${tmp}`;
690
- separator = ",";
691
- }
692
- }
693
- if (keyLength > maximumBreadth) {
694
- const removedKeys = keyLength - maximumBreadth;
695
- res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
696
- }
697
- stack.pop();
698
- return `{${res}}`;
699
- }
700
- case "number":
701
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
702
- case "boolean":
703
- return value === true ? "true" : "false";
704
- case "undefined":
705
- return void 0;
706
- case "bigint":
707
- if (bigint) {
708
- return String(value);
709
- }
710
- default:
711
- return fail ? fail(value) : void 0;
712
- }
713
- }
714
- function stringify2(value, replacer, space) {
715
- if (arguments.length > 1) {
716
- let spacer = "";
717
- if (typeof space === "number") {
718
- spacer = " ".repeat(Math.min(space, 10));
719
- } else if (typeof space === "string") {
720
- spacer = space.slice(0, 10);
721
- }
722
- if (replacer != null) {
723
- if (typeof replacer === "function") {
724
- return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
725
- }
726
- if (Array.isArray(replacer)) {
727
- return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
728
- }
729
- }
730
- if (spacer.length !== 0) {
731
- return stringifyIndent("", value, [], spacer, "");
732
- }
733
- }
734
- return stringifySimple("", value, []);
735
- }
736
- return stringify2;
737
- }
738
- })(safeStableStringify, safeStableStringify.exports);
739
- var safeStableStringifyExports = safeStableStringify.exports;
740
- const cjsModule = /* @__PURE__ */ getDefaultExportFromCjs(safeStableStringifyExports);
741
- cjsModule.configure;
742
- let getRandomValues;
743
- const rnds8 = new Uint8Array(16);
744
- function rng() {
745
- if (!getRandomValues) {
746
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
747
- if (!getRandomValues) {
748
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
749
- }
750
- }
751
- return getRandomValues(rnds8);
752
- }
753
- const byteToHex = [];
754
- for (let i = 0; i < 256; ++i) {
755
- byteToHex.push((i + 256).toString(16).slice(1));
756
- }
757
- function unsafeStringify(arr, offset = 0) {
758
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
759
- }
760
- const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
761
- const native = {
762
- randomUUID
763
- };
764
- function v4(options, buf, offset) {
765
- if (native.randomUUID && !buf && !options) {
766
- return native.randomUUID();
767
- }
768
- options = options || {};
769
- const rnds = options.random || (options.rng || rng)();
770
- rnds[6] = rnds[6] & 15 | 64;
771
- rnds[8] = rnds[8] & 63 | 128;
772
- return unsafeStringify(rnds);
773
- }
774
- function writeFile(path$1, name, data) {
775
- const filePath = path.join(path$1, name);
776
- fs.mkdirSync(path$1, { recursive: true });
777
- return new Promise((resolve, reject) => {
778
- try {
779
- fs.writeFile(filePath, data, {}, (err) => {
780
- if (err) {
781
- reject(err);
782
- } else {
783
- resolve(filePath);
784
- }
785
- });
786
- } catch (error) {
787
- reject(error);
788
- }
789
- });
790
- }
791
- function readFile(path2) {
792
- return fs.readFileSync(path2);
793
- }
794
- function fetchFile(url) {
795
- return new Promise((resolve, reject) => {
796
- https.get(url, (resp) => {
797
- const data = [];
798
- const mimeType = resp.headers["content-type"];
799
- resp.on("data", (chunk) => {
800
- data.push(chunk);
801
- });
802
- resp.on("end", () => {
803
- resolve({ buffer: Buffer.concat(data), mimeType });
804
- });
805
- }).on("error", (err) => {
806
- reject(err);
807
- });
808
- });
809
- }
810
- const getFile = async (file) => {
811
- return readFile(file);
812
- };
813
- const hash = (data, algorithm = "sha1") => {
814
- return crypto$1.createHash(algorithm).update(data).digest("base64");
815
- };
816
- function getUnixTimestamp(date) {
817
- return (new Date(date).getTime() / 1e3).toFixed(0);
818
- }
819
- function buildOperationSignatureParams({
820
- documentId,
821
- signer,
822
- operation,
823
- previousStateHash
824
- }) {
825
- const { timestamp, scope, id, type } = operation;
826
- return [
827
- getUnixTimestamp(timestamp),
828
- // timestamp,
829
- signer.app.key,
830
- // signer public key
831
- hash(
832
- // hash (docID, scope, operationID, operationName, operationInput)
833
- [documentId, scope, id, type, cjsModule(operation.input)].join("")
834
- ),
835
- previousStateHash
836
- // state hash that the operation was applied to
837
- ];
838
- }
839
- const textEncode = new TextEncoder();
840
- function buildOperationSignatureMessage(params) {
841
- const message = params.join("");
842
- const prefix = "Signed Operation:\n" + message.length.toString();
843
- return textEncode.encode(prefix + message);
844
- }
845
- function ab2hex(ab) {
846
- return Array.prototype.map.call(new Uint8Array(ab), (x) => ("00" + x.toString(16)).slice(-2)).join("");
847
- }
848
- function hex2ab(hex) {
849
- var _a;
850
- return new Uint8Array(
851
- ((_a = hex.match(/[\da-f]{2}/gi)) == null ? void 0 : _a.map(function(h) {
852
- return parseInt(h, 16);
853
- })) ?? []
854
- );
855
- }
856
- async function buildOperationSignature(context, signMethod) {
857
- const params = buildOperationSignatureParams(context);
858
- const message = buildOperationSignatureMessage(params);
859
- const signature = await signMethod(message);
860
- return [...params, `0x${ab2hex(signature)}`];
861
- }
862
- async function buildSignedOperation(action, reducer, document, context, signHandler) {
863
- var _a, _b;
864
- const result = reducer(document, action, void 0, {
865
- reuseHash: true,
866
- reuseOperationResultingState: true
867
- });
868
- const operation = result.operations[action.scope].at(-1);
869
- if (!operation) {
870
- throw new Error("Action was not applied");
871
- }
872
- const previousStateHash = ((_a = result.operations[action.scope].at(-2)) == null ? void 0 : _a.hash) ?? "";
873
- const signature = await buildOperationSignature(
874
- {
875
- ...context,
876
- operation,
877
- previousStateHash
878
- },
879
- signHandler
880
- );
881
- return {
882
- ...operation,
883
- context: {
884
- ...operation.context,
885
- signer: {
886
- ...(_b = operation.context) == null ? void 0 : _b.signer,
887
- ...context.signer,
888
- signatures: [...context.signer.signatures ?? [], signature]
889
- }
890
- }
891
- };
892
- }
893
- async function verifyOperationSignature(signature, signer, verifyHandler) {
894
- const publicKey = signer.app.key;
895
- const params = signature.slice(0, 4);
896
- const signatureBytes = hex2ab(signature[4]);
897
- const expectedMessage = buildOperationSignatureMessage(params);
898
- return verifyHandler(publicKey, signatureBytes, expectedMessage);
899
- }
900
- const types = { "application/andrew-inset": ["ez"], "application/appinstaller": ["appinstaller"], "application/applixware": ["aw"], "application/appx": ["appx"], "application/appxbundle": ["appxbundle"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/automationml-aml+xml": ["aml"], "application/automationml-amlx+zip": ["amlx"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cpl+xml": ["cpl"], "application/cu-seeme": ["cu"], "application/cwl": ["cwl"], "application/dash+xml": ["mpd"], "application/dash-patch+xml": ["mpp"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdf": ["fdf"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["*js"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/media-policy-dataset+xml": ["mpf"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["*mp4", "*mpg4", "mp4s", "m4p"], "application/msix": ["msix"], "application/msixbundle": ["msixbundle"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-keys": ["asc"], "application/pgp-signature": ["sig", "*asc"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/sql": ["sql"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/watcherinfo+xml": ["wif"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xfdf": ["xfdf"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/aac": ["adts", "aac"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avci": ["avci"], "image/avcs": ["avcs"], "image/avif": ["avif"], "image/bmp": ["bmp", "dib"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/dpx": ["dpx"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm", "jpgm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/jt": ["jt"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/prc": ["prc"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/u3d": ["u3d"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/javascript": ["js", "mjs"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["md", "markdown"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/wgsl": ["wgsl"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "*jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
901
- Object.freeze(types);
902
- var __classPrivateFieldGet = function(receiver, state, kind, f) {
903
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
904
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
905
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
906
- };
907
- var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
908
- class Mime {
909
- constructor(...args) {
910
- _Mime_extensionToType.set(this, /* @__PURE__ */ new Map());
911
- _Mime_typeToExtension.set(this, /* @__PURE__ */ new Map());
912
- _Mime_typeToExtensions.set(this, /* @__PURE__ */ new Map());
913
- for (const arg of args) {
914
- this.define(arg);
915
- }
916
- }
917
- define(typeMap, force = false) {
918
- for (let [type, extensions] of Object.entries(typeMap)) {
919
- type = type.toLowerCase();
920
- extensions = extensions.map((ext) => ext.toLowerCase());
921
- if (!__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").has(type)) {
922
- __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").set(type, /* @__PURE__ */ new Set());
923
- }
924
- const allExtensions = __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type);
925
- let first = true;
926
- for (let extension of extensions) {
927
- const starred = extension.startsWith("*");
928
- extension = starred ? extension.slice(1) : extension;
929
- allExtensions == null ? void 0 : allExtensions.add(extension);
930
- if (first) {
931
- __classPrivateFieldGet(this, _Mime_typeToExtension, "f").set(type, extension);
932
- }
933
- first = false;
934
- if (starred)
935
- continue;
936
- const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
937
- if (currentType && currentType != type && !force) {
938
- throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
939
- }
940
- __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
941
- }
942
- }
943
- return this;
944
- }
945
- getType(path2) {
946
- if (typeof path2 !== "string")
947
- return null;
948
- const last = path2.replace(/^.*[/\\]/, "").toLowerCase();
949
- const ext = last.replace(/^.*\./, "").toLowerCase();
950
- const hasPath = last.length < path2.length;
951
- const hasDot = ext.length < last.length - 1;
952
- if (!hasDot && hasPath)
953
- return null;
954
- return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
955
- }
956
- getExtension(type) {
957
- var _a;
958
- if (typeof type !== "string")
959
- return null;
960
- type = (_a = type == null ? void 0 : type.split) == null ? void 0 : _a.call(type, ";")[0];
961
- return (type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null;
962
- }
963
- getAllExtensions(type) {
964
- if (typeof type !== "string")
965
- return null;
966
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
967
- }
968
- _freeze() {
969
- this.define = () => {
970
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
971
- };
972
- Object.freeze(this);
973
- for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
974
- Object.freeze(extensions);
975
- }
976
- return this;
977
- }
978
- _getTestState() {
979
- return {
980
- types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
981
- extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f")
982
- };
983
- }
984
- }
985
- _Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
986
- const mime = new Mime(types)._freeze();
987
- function validateOperations(operations) {
988
- const errors = [];
989
- const scopes = Object.keys(operations);
990
- for (const scope of scopes) {
991
- const ops = operations[scope].sort((a, b) => a.index - b.index);
992
- let opIndex = -1;
993
- for (let i = 0; i < ops.length; i++) {
994
- opIndex = opIndex + 1 + ops[i].skip;
995
- if (ops[i].index !== opIndex) {
996
- errors.push({
997
- message: `Invalid operation index ${ops[i].index} at position ${i}`,
998
- details: {
999
- position: i,
1000
- operation: ops[i],
1001
- scope: ops[i].scope
1002
- }
1003
- });
1004
- }
1005
- }
1006
- }
1007
- return errors;
1008
- }
1009
- var IntegrityIssueType = /* @__PURE__ */ ((IntegrityIssueType2) => {
1010
- IntegrityIssueType2["UNEXPECTED_INDEX"] = "UNEXPECTED_INDEX";
1011
- return IntegrityIssueType2;
1012
- })(IntegrityIssueType || {});
1013
- var IntegrityIssueSubType = /* @__PURE__ */ ((IntegrityIssueSubType2) => {
1014
- IntegrityIssueSubType2["DUPLICATED_INDEX"] = "DUPLICATED_INDEX";
1015
- IntegrityIssueSubType2["MISSING_INDEX"] = "MISSING_INDEX";
1016
- return IntegrityIssueSubType2;
1017
- })(IntegrityIssueSubType || {});
1018
- function checkCleanedOperationsIntegrity(sortedOperations) {
1019
- const result = [];
1020
- let currentIndex = -1;
1021
- for (const nextOperation of sortedOperations) {
1022
- const nextIndex = nextOperation.index - nextOperation.skip;
1023
- if (nextIndex !== currentIndex + 1) {
1024
- result.push({
1025
- operation: {
1026
- index: nextOperation.index,
1027
- skip: nextOperation.skip
1028
- },
1029
- issue: "UNEXPECTED_INDEX",
1030
- category: nextIndex > currentIndex + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
1031
- message: `Expected index ${currentIndex + 1} with skip 0 or equivalent, got index ${nextOperation.index} with skip ${nextOperation.skip}`
1032
- });
1033
- }
1034
- currentIndex = nextOperation.index;
1035
- }
1036
- return result;
1037
- }
1038
- function garbageCollect(sortedOperations) {
1039
- var _a, _b, _c;
1040
- const result = [];
1041
- let i = sortedOperations.length - 1;
1042
- while (i > -1) {
1043
- result.unshift(sortedOperations[i]);
1044
- const skipUntil = (((_a = sortedOperations[i]) == null ? void 0 : _a.index) || 0) - (((_b = sortedOperations[i]) == null ? void 0 : _b.skip) || 0) - 1;
1045
- let j = i - 1;
1046
- while (j > -1 && (((_c = sortedOperations[j]) == null ? void 0 : _c.index) || 0) > skipUntil) {
1047
- j--;
1048
- }
1049
- i = j;
1050
- }
1051
- return result;
1052
- }
1053
- function addUndo(sortedOperations) {
1054
- const operationsCopy = [...sortedOperations];
1055
- const latestOperation = operationsCopy[operationsCopy.length - 1];
1056
- if (!latestOperation) return operationsCopy;
1057
- if (latestOperation.type === "NOOP") {
1058
- operationsCopy.push({
1059
- ...latestOperation,
1060
- index: latestOperation.index,
1061
- type: "NOOP",
1062
- skip: nextSkipNumber(sortedOperations)
1063
- });
1064
- } else {
1065
- operationsCopy.push({
1066
- type: "NOOP",
1067
- index: latestOperation.index + 1,
1068
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1069
- input: {},
1070
- skip: 1,
1071
- scope: latestOperation.scope,
1072
- hash: latestOperation.hash
1073
- });
1074
- }
1075
- return operationsCopy;
1076
- }
1077
- function sortOperations$1(operations) {
1078
- return operations.slice().sort((a, b) => a.skip - b.skip).sort((a, b) => a.index - b.index);
1079
- }
1080
- const reshuffleByTimestamp = (startIndex, opsA, opsB) => {
1081
- return [...opsA, ...opsB].sort(
1082
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
1083
- ).map((op, i) => ({
1084
- ...op,
1085
- index: startIndex.index + i,
1086
- skip: i === 0 ? startIndex.skip : 0
1087
- }));
1088
- };
1089
- const reshuffleByTimestampAndIndex = (startIndex, opsA, opsB) => {
1090
- return [...opsA, ...opsB].sort(
1091
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
1092
- ).sort((a, b) => a.index - b.index).map((op, i) => ({
1093
- ...op,
1094
- index: startIndex.index + i,
1095
- skip: i === 0 ? startIndex.skip : 0
1096
- }));
1097
- };
1098
- function operationsAreEqual(op1, op2) {
1099
- return cjsModule(op1) === cjsModule(op2);
1100
- }
1101
- function attachBranch(trunk, newBranch) {
1102
- const trunkCopy = garbageCollect(sortOperations$1(trunk.slice()));
1103
- const newOperations = garbageCollect(sortOperations$1(newBranch.slice()));
1104
- if (trunkCopy.length < 1) {
1105
- return [newOperations, []];
1106
- }
1107
- const result = [];
1108
- let enteredBranch = false;
1109
- while (newOperations.length > 0) {
1110
- const newOperationCandidate = newOperations[0];
1111
- let nextTrunkOperation = trunkCopy.shift();
1112
- while (nextTrunkOperation && precedes(nextTrunkOperation, newOperationCandidate)) {
1113
- result.push(nextTrunkOperation);
1114
- nextTrunkOperation = trunkCopy.shift();
1115
- }
1116
- if (!nextTrunkOperation) {
1117
- enteredBranch = true;
1118
- } else if (!enteredBranch) {
1119
- if (operationsAreEqual(nextTrunkOperation, newOperationCandidate)) {
1120
- newOperations.shift();
1121
- result.push(nextTrunkOperation);
1122
- } else {
1123
- trunkCopy.unshift(nextTrunkOperation);
1124
- enteredBranch = true;
1125
- }
1126
- }
1127
- if (enteredBranch) {
1128
- let nextAppend = newOperations.shift();
1129
- while (nextAppend) {
1130
- result.push(nextAppend);
1131
- nextAppend = newOperations.shift();
1132
- }
1133
- }
1134
- }
1135
- if (!enteredBranch) {
1136
- let nextAppend = trunkCopy.shift();
1137
- while (nextAppend) {
1138
- result.push(nextAppend);
1139
- nextAppend = trunkCopy.shift();
1140
- }
1141
- }
1142
- return [garbageCollect(result), trunkCopy];
1143
- }
1144
- function precedes(op1, op2) {
1145
- return op1.index < op2.index || op1.index === op2.index && op1.id === op2.id && op1.skip < op2.skip;
1146
- }
1147
- function split(sortedTargetOperations, sortedMergeOperations) {
1148
- const commonOperations = [];
1149
- const targetDiffOperations = [];
1150
- const mergeDiffOperations = [];
1151
- const maxLength = Math.max(
1152
- sortedTargetOperations.length,
1153
- sortedMergeOperations.length
1154
- );
1155
- let splitHappened = false;
1156
- for (let i = 0; i < maxLength; i++) {
1157
- const targetOperation = sortedTargetOperations[i];
1158
- const mergeOperation = sortedMergeOperations[i];
1159
- if (targetOperation && mergeOperation) {
1160
- if (!splitHappened && operationsAreEqual(targetOperation, mergeOperation)) {
1161
- commonOperations.push(targetOperation);
1162
- } else {
1163
- splitHappened = true;
1164
- targetDiffOperations.push(targetOperation);
1165
- mergeDiffOperations.push(mergeOperation);
1166
- }
1167
- } else if (targetOperation) {
1168
- targetDiffOperations.push(targetOperation);
1169
- } else if (mergeOperation) {
1170
- mergeDiffOperations.push(mergeOperation);
1171
- }
1172
- }
1173
- return [commonOperations, targetDiffOperations, mergeDiffOperations];
1174
- }
1175
- function merge(sortedTargetOperations, sortedMergeOperations, reshuffle) {
1176
- const [_commonOperations, _targetOperations, _mergeOperations] = split(
1177
- garbageCollect(sortedTargetOperations),
1178
- garbageCollect(sortedMergeOperations)
1179
- );
1180
- const maxCommonIndex = getMaxIndex(_commonOperations);
1181
- const nextIndex = 1 + Math.max(
1182
- maxCommonIndex,
1183
- getMaxIndex(_targetOperations),
1184
- getMaxIndex(_mergeOperations)
1185
- );
1186
- const filteredMergeOperations = filterDuplicatedOperations(
1187
- _mergeOperations,
1188
- _targetOperations
1189
- );
1190
- const newOperationHistory = reshuffle(
1191
- {
1192
- index: nextIndex,
1193
- skip: nextIndex - (maxCommonIndex + 1)
1194
- },
1195
- _targetOperations,
1196
- filteredMergeOperations
1197
- );
1198
- return _commonOperations.concat(newOperationHistory);
1199
- }
1200
- function getMaxIndex(sortedOperations) {
1201
- const lastElement = sortedOperations[sortedOperations.length - 1];
1202
- if (!lastElement) {
1203
- return -1;
1204
- }
1205
- return lastElement.index;
1206
- }
1207
- function nextSkipNumber(sortedOperations) {
1208
- var _a, _b, _c;
1209
- if (sortedOperations.length < 1) {
1210
- return -1;
1211
- }
1212
- const cleanedOperations = garbageCollect(sortedOperations);
1213
- let nextSkip = (((_a = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _a.skip) || 0) + 1;
1214
- if (cleanedOperations.length > 1) {
1215
- nextSkip += ((_b = cleanedOperations[cleanedOperations.length - 2]) == null ? void 0 : _b.skip) || 0;
1216
- }
1217
- return (((_c = cleanedOperations[cleanedOperations.length - 1]) == null ? void 0 : _c.index) || -1) < nextSkip ? -1 : nextSkip;
1218
- }
1219
- const checkOperationsIntegrity = (operations) => {
1220
- return checkCleanedOperationsIntegrity(
1221
- garbageCollect(sortOperations$1(operations))
1222
- );
1223
- };
1224
- const groupOperationsByScope = (operations) => {
1225
- const result = operations.reduce((acc, operation) => {
1226
- var _a;
1227
- if (!acc[operation.scope]) {
1228
- acc[operation.scope] = [];
1229
- }
1230
- (_a = acc[operation.scope]) == null ? void 0 : _a.push(operation);
1231
- return acc;
1232
- }, {});
1233
- return result;
1234
- };
1235
- const prepareOperations = (operationsHistory, newOperations) => {
1236
- var _a;
1237
- const result = {
1238
- integrityIssues: [],
1239
- validOperations: [],
1240
- invalidOperations: [],
1241
- duplicatedOperations: []
1242
- };
1243
- const sortedOperationsHistory = sortOperations$1(operationsHistory);
1244
- const sortedOperations = sortOperations$1(newOperations);
1245
- const integrityErrors = checkCleanedOperationsIntegrity([
1246
- ...sortedOperationsHistory,
1247
- ...sortedOperations
1248
- ]);
1249
- const missingIndexErrors = integrityErrors.filter(
1250
- (integrityIssue) => integrityIssue.category === "MISSING_INDEX"
1251
- /* MISSING_INDEX */
1252
- );
1253
- const firstMissingIndexOperation = (_a = [...missingIndexErrors].sort((a, b) => b.operation.index - a.operation.index).pop()) == null ? void 0 : _a.operation;
1254
- for (const newOperation of sortedOperations) {
1255
- if (firstMissingIndexOperation && newOperation.index >= firstMissingIndexOperation.index) {
1256
- result.invalidOperations.push(newOperation);
1257
- continue;
1258
- }
1259
- const isDuplicatedOperation = integrityErrors.some((integrityError) => {
1260
- return integrityError.operation.index === newOperation.index && integrityError.operation.skip === newOperation.skip && integrityError.category === "DUPLICATED_INDEX";
1261
- });
1262
- if (isDuplicatedOperation) {
1263
- result.duplicatedOperations.push(newOperation);
1264
- continue;
1265
- }
1266
- result.validOperations.push(newOperation);
1267
- }
1268
- result.integrityIssues.push(...integrityErrors);
1269
- return result;
1270
- };
1271
- function removeExistingOperations(newOperations, operationsHistory) {
1272
- return newOperations.filter((newOperation) => {
1273
- return !operationsHistory.some((historyOperation) => {
1274
- return newOperation.type === "NOOP" && newOperation.skip === 0 && newOperation.index === historyOperation.index || newOperation.index === historyOperation.index && newOperation.skip === historyOperation.skip && newOperation.scope === historyOperation.scope && newOperation.hash === historyOperation.hash && newOperation.type === historyOperation.type;
1275
- });
1276
- });
1277
- }
1278
- function skipHeaderOperations(operations, skipHeaderOperation) {
1279
- const [lastOperation] = sortOperations$1(operations).slice(-1);
1280
- const lastIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
1281
- const nextIndex = lastIndex + 1;
1282
- const skipOperationIndex = {
1283
- ...skipHeaderOperation,
1284
- index: skipHeaderOperation.index ?? nextIndex
1285
- };
1286
- if (skipOperationIndex.index < lastIndex) {
1287
- throw new Error(
1288
- `The skip header operation index must be greater than or equal to ${lastIndex}`
1289
- );
1290
- }
1291
- const clearedOperations = garbageCollect(
1292
- sortOperations$1([...operations, skipOperationIndex])
1293
- );
1294
- return (clearedOperations || []).slice(0, -1);
1295
- }
1296
- function garbageCollectDocumentOperations(documentOperations) {
1297
- const clearedOperations = Object.entries(documentOperations).reduce(
1298
- (acc, entry) => {
1299
- const [scope, ops] = entry;
1300
- return {
1301
- ...acc,
1302
- [scope]: garbageCollect(sortOperations$1(ops))
1303
- };
1304
- },
1305
- {}
1306
- );
1307
- return {
1308
- ...clearedOperations
1309
- };
1310
- }
1311
- function filterDuplicatedOperations(targetOperations, sourceOperations) {
1312
- return targetOperations.filter((op) => {
1313
- if (op.id) {
1314
- return !sourceOperations.some((targetOp) => targetOp.id === op.id);
1315
- }
1316
- return true;
1317
- });
1318
- }
1319
- function filterDocumentOperationsResultingState(documentOperations) {
1320
- if (!documentOperations) {
1321
- return {};
1322
- }
1323
- const entries = Object.entries(documentOperations);
1324
- return entries.reduce(
1325
- (acc, [scope, operations]) => ({
1326
- ...acc,
1327
- [scope]: operations.map((op) => {
1328
- const { resultingState, ...restProps } = op;
1329
- return restProps;
1330
- })
1331
- }),
1332
- {}
1333
- );
1334
- }
1335
- function diffOperations(clearedOperationsA, clearedOperationsB) {
1336
- return clearedOperationsA.filter(
1337
- (operationA) => !clearedOperationsB.some(
1338
- (operationB) => operationA.index === operationB.index
1339
- )
1340
- );
1341
- }
1342
- const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1343
- __proto__: null,
1344
- IntegrityIssueSubType,
1345
- IntegrityIssueType,
1346
- addUndo,
1347
- attachBranch,
1348
- checkCleanedOperationsIntegrity,
1349
- checkOperationsIntegrity,
1350
- diffOperations,
1351
- filterDocumentOperationsResultingState,
1352
- filterDuplicatedOperations,
1353
- garbageCollect,
1354
- garbageCollectDocumentOperations,
1355
- groupOperationsByScope,
1356
- merge,
1357
- nextSkipNumber,
1358
- operationsAreEqual,
1359
- precedes,
1360
- prepareOperations,
1361
- removeExistingOperations,
1362
- reshuffleByTimestamp,
1363
- reshuffleByTimestampAndIndex,
1364
- skipHeaderOperations,
1365
- sortOperations: sortOperations$1,
1366
- split
1367
- }, Symbol.toStringTag, { value: "Module" }));
1368
- const createZip = async (document) => {
1369
- const zip = new JSZip();
1370
- const { name, revision, documentType, created, lastModified } = document;
1371
- const header = {
1372
- name,
1373
- revision,
1374
- documentType,
1375
- created,
1376
- lastModified
1377
- };
1378
- zip.file("header.json", JSON.stringify(header, null, 2));
1379
- zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
1380
- zip.file(
1381
- "operations.json",
1382
- JSON.stringify(
1383
- filterDocumentOperationsResultingState(document.operations),
1384
- null,
1385
- 2
1386
- )
1387
- );
1388
- if (document.attachments) {
1389
- const attachments = Object.keys(document.attachments);
1390
- attachments.forEach((key) => {
1391
- const { data, ...attributes } = document.attachments[key];
1392
- zip.file(key, data, {
1393
- base64: true,
1394
- createFolders: true,
1395
- comment: JSON.stringify(attributes)
1396
- });
1397
- });
1398
- }
1399
- return zip;
1400
- };
1401
- const saveToFile = async (document, path2, extension, name) => {
1402
- const zip = await createZip(document);
1403
- const file = await zip.generateAsync({
1404
- type: "uint8array",
1405
- streamFiles: true
1406
- });
1407
- const fileName = name ?? document.name;
1408
- const fileExtension = `.${extension}.zip`;
1409
- return writeFile(
1410
- path2,
1411
- fileName.endsWith(fileExtension) ? fileName : `${fileName}${fileExtension}`,
1412
- file
1413
- );
1414
- };
1415
- const saveToFileHandle = async (document, input) => {
1416
- const zip = await createZip(document);
1417
- const blob = await zip.generateAsync({ type: "blob" });
1418
- const writable = await input.createWritable();
1419
- await writable.write(blob);
1420
- await writable.close();
1421
- };
1422
- const loadFromFile = async (path2, reducer, options) => {
1423
- const file = readFile(path2);
1424
- return loadFromInput(file, reducer, options);
1425
- };
1426
- const loadFromInput = async (input, reducer, options) => {
1427
- const zip = new JSZip();
1428
- await zip.loadAsync(input);
1429
- return loadFromZip(zip, reducer, options);
1430
- };
1431
- async function loadFromZip(zip, reducer, options) {
1432
- const initialStateZip = zip.file("state.json");
1433
- if (!initialStateZip) {
1434
- throw new Error("Initial state not found");
1435
- }
1436
- const initialStateStr = await initialStateZip.async("string");
1437
- const initialState = JSON.parse(initialStateStr);
1438
- const headerZip = zip.file("header.json");
1439
- let header = void 0;
1440
- if (headerZip) {
1441
- header = JSON.parse(await headerZip.async("string"));
1442
- }
1443
- const operationsZip = zip.file("operations.json");
1444
- if (!operationsZip) {
1445
- throw new Error("Operations history not found");
1446
- }
1447
- const operations = JSON.parse(
1448
- await operationsZip.async("string")
1449
- );
1450
- const clearedOperations = garbageCollectDocumentOperations(operations);
1451
- const operationsError = validateOperations(clearedOperations);
1452
- if (operationsError.length) {
1453
- const errorMessages = operationsError.map((err) => err.message);
1454
- throw new Error(errorMessages.join("\n"));
1455
- }
1456
- let result = replayDocument(
1457
- initialState,
1458
- clearedOperations,
1459
- reducer,
1460
- void 0,
1461
- header,
1462
- {},
1463
- options
1464
- );
1465
- if (header) {
1466
- result = {
1467
- ...result,
1468
- ...header
1469
- };
1470
- }
1471
- return result;
1472
- }
1473
- function getFileAttributes(file) {
1474
- const extension = file.replace(/^.*\./, "") || void 0;
1475
- const fileName = file.replace(/^.*[/\\]/, "") || void 0;
1476
- return { extension, fileName };
1477
- }
1478
- async function getRemoteFile(url) {
1479
- const { buffer, mimeType = "application/octet-stream" } = await fetchFile(url);
1480
- const attributes = getFileAttributes(url);
1481
- const data = buffer.toString("base64");
1482
- return {
1483
- data,
1484
- hash: hash(data),
1485
- mimeType,
1486
- ...attributes
1487
- };
1488
- }
1489
- async function getLocalFile(path2) {
1490
- const buffer = await getFile(path2);
1491
- const mimeType = mime.getType(path2) || "application/octet-stream";
1492
- const attributes = getFileAttributes(path2);
1493
- const data = buffer.toString("base64");
1494
- return { data, hash: hash(data), mimeType, ...attributes };
1495
- }
1496
- function setNameOperation(document, name) {
1497
- return { ...document, name };
1498
- }
1499
- function undoOperation(document, action, skip) {
1500
- const { scope, input } = action;
1501
- const defaultResult = {
1502
- document,
1503
- action,
1504
- skip,
1505
- reuseLastOperationIndex: false
1506
- };
1507
- return mutative.create(defaultResult, (draft) => {
1508
- const operations = [...document.operations[scope]];
1509
- const sortedOperations = sortOperations$1(operations);
1510
- draft.action = noop(scope);
1511
- const lastOperation = sortedOperations.at(-1);
1512
- let nextIndex = (lastOperation == null ? void 0 : lastOperation.index) ?? -1;
1513
- const isNewNoop = (lastOperation == null ? void 0 : lastOperation.type) !== "NOOP";
1514
- if (isNewNoop) {
1515
- nextIndex = nextIndex + 1;
1516
- } else {
1517
- draft.reuseLastOperationIndex = true;
1518
- }
1519
- const nextOperationHistory = isNewNoop ? [...sortedOperations, { index: nextIndex, skip: 0 }] : sortedOperations;
1520
- draft.skip = nextSkipNumber(nextOperationHistory);
1521
- if (lastOperation && draft.skip > lastOperation.skip + 1) {
1522
- draft.skip = draft.skip + 1;
1523
- }
1524
- if (draft.skip < 0) {
1525
- throw new Error(
1526
- `Cannot undo: you can't undo more operations than the ones in the scope history`
1527
- );
1528
- }
1529
- });
1530
- }
1531
- function redoOperation(document, action, skip) {
1532
- const { scope, input } = action;
1533
- const defaultResult = {
1534
- document,
1535
- action,
1536
- skip,
1537
- reuseLastOperationIndex: false
1538
- };
1539
- return mutative.create(defaultResult, (draft) => {
1540
- if (draft.skip > 0) {
1541
- throw new Error(
1542
- `Cannot redo: skip value from reducer cannot be used with REDO action`
1543
- );
1544
- }
1545
- if (input > 1) {
1546
- throw new Error(`Cannot redo: you can only redo one operation at a time`);
1547
- }
1548
- if (input < 1) {
1549
- throw new Error(`Invalid REDO action: invalid redo input value`);
1550
- }
1551
- if (draft.document.clipboard.length < 1) {
1552
- throw new Error(`Cannot redo: no operations in the clipboard`);
1553
- }
1554
- const operationIndex = draft.document.clipboard.findLastIndex(
1555
- (op) => op.scope === scope
1556
- );
1557
- if (operationIndex < 0) {
1558
- throw new Error(
1559
- `Cannot redo: no operations in clipboard for scope "${scope}"`
1560
- );
1561
- }
1562
- const operation = draft.document.clipboard.splice(operationIndex, 1)[0];
1563
- draft.action = mutative.castDraft({
1564
- type: operation.type,
1565
- scope: operation.scope,
1566
- input: operation.input
1567
- });
1568
- });
1569
- }
1570
- function pruneOperation(document, action, wrappedReducer) {
1571
- const { scope } = action;
1572
- const operations = document.operations[scope];
1573
- let {
1574
- input: { start, end }
1575
- } = action;
1576
- start = start || 0;
1577
- end = end || operations.length;
1578
- const actionsToPrune = operations.slice(start, end);
1579
- const actionsToKeepStart = operations.slice(0, start);
1580
- const actionsToKeepEnd = operations.slice(end);
1581
- const newDocument = replayOperations(
1582
- document.initialState,
1583
- {
1584
- ...document.operations,
1585
- [scope]: actionsToKeepStart.concat(actionsToPrune)
1586
- },
1587
- wrappedReducer
1588
- );
1589
- const { name, state: newState } = newDocument;
1590
- const loadStateIndex = actionsToKeepStart.length;
1591
- const loadStateTimestamp = actionsToKeepStart.length ? actionsToKeepStart[actionsToKeepStart.length - 1].timestamp : actionsToKeepEnd.length ? actionsToKeepEnd[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
1592
- return replayOperations(
1593
- document.initialState,
1594
- {
1595
- ...document.operations,
1596
- [scope]: [
1597
- ...actionsToKeepStart,
1598
- {
1599
- ...loadState({ name, state: newState }, actionsToPrune.length),
1600
- timestamp: loadStateTimestamp,
1601
- index: loadStateIndex,
1602
- hash: hashDocument({ state: newState }, "global")
1603
- },
1604
- ...actionsToKeepEnd.map((action2, index) => ({
1605
- ...action2,
1606
- index: loadStateIndex + index + 1
1607
- }))
1608
- ]
1609
- },
1610
- wrappedReducer
1611
- );
1612
- }
1613
- function loadStateOperation(oldDocument, newDocument) {
1614
- return {
1615
- ...oldDocument,
1616
- name: newDocument.name,
1617
- state: newDocument.state ?? { global: {}, local: {} }
1618
- };
1619
- }
1620
- const SET_NAME = "SET_NAME";
1621
- const UNDO = "UNDO";
1622
- const REDO = "REDO";
1623
- const PRUNE = "PRUNE";
1624
- const LOAD_STATE = "LOAD_STATE";
1625
- const NOOP = "NOOP";
1626
- function getNextRevision(document, action) {
1627
- let latestOperation;
1628
- if ("index" in action) {
1629
- latestOperation = { ...action };
1630
- } else {
1631
- latestOperation = document.operations[action.scope].at(-1);
1632
- }
1633
- return ((latestOperation == null ? void 0 : latestOperation.index) ?? -1) + 1;
1634
- }
1635
- function updateHeader(document, action) {
1636
- return {
1637
- ...document,
1638
- revision: {
1639
- ...document.revision,
1640
- [action.scope]: getNextRevision(document, action)
1641
- },
1642
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
1643
- };
1644
- }
1645
- function updateOperations(document, action, skip = 0, reuseLastOperationIndex = false) {
1646
- if ([UNDO, REDO, PRUNE].includes(action.type)) {
1647
- return document;
1648
- }
1649
- const { scope } = action;
1650
- const operations = document.operations[scope].slice();
1651
- let operationId;
1652
- const latestOperation = operations.at(-1);
1653
- const lastOperationIndex = (latestOperation == null ? void 0 : latestOperation.index) ?? -1;
1654
- let nextIndex = reuseLastOperationIndex ? lastOperationIndex : lastOperationIndex + 1;
1655
- if ("index" in action) {
1656
- if (action.index - skip > nextIndex) {
1657
- throw new Error(
1658
- `Missing operations: expected ${nextIndex} with skip 0 or equivalent, got index ${action.index} with skip ${skip}`
1659
- );
1660
- }
1661
- nextIndex = action.index;
1662
- operationId = action.id;
1663
- } else {
1664
- operationId = "id" in action ? action.id : v4();
1665
- }
1666
- operations.push({
1667
- ...action,
1668
- id: operationId,
1669
- index: nextIndex,
1670
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1671
- hash: "",
1672
- scope,
1673
- skip,
1674
- error: void 0
1675
- });
1676
- return {
1677
- ...document,
1678
- operations: { ...document.operations, [scope]: operations }
1679
- };
1680
- }
1681
- function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
1682
- let newDocument = updateOperations(
1683
- document,
1684
- action,
1685
- skip,
1686
- reuseLastOperationIndex
1687
- );
1688
- newDocument = updateHeader(newDocument, action);
1689
- return newDocument;
1690
- }
1691
- function _baseReducer(document, action, wrappedReducer) {
1692
- BaseActionSchema().parse(action);
1693
- switch (action.type) {
1694
- case SET_NAME:
1695
- return setNameOperation(document, action.input);
1696
- case PRUNE:
1697
- return pruneOperation(document, action, wrappedReducer);
1698
- case LOAD_STATE:
1699
- return loadStateOperation(document, action.input.state);
1700
- default:
1701
- return document;
1702
- }
1703
- }
1704
- function processUndoRedo(document, action, skip) {
1705
- switch (action.type) {
1706
- case UNDO:
1707
- return undoOperation(document, action, skip);
1708
- case REDO:
1709
- return redoOperation(document, action, skip);
1710
- default:
1711
- return { document, action, skip, reuseLastOperationIndex: false };
1712
- }
1713
- }
1714
- function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
1715
- const scope = action.scope;
1716
- const latestOperation = document.operations[scope].at(-1);
1717
- if (!latestOperation) return document;
1718
- const documentOperations = garbageCollectDocumentOperations({
1719
- ...document.operations,
1720
- [scope]: skipHeaderOperations(
1721
- document.operations[scope],
1722
- latestOperation
1723
- )
1724
- });
1725
- let scopeState = void 0;
1726
- const lastRemainingOperation = documentOperations[scope].at(-1);
1727
- if (reuseOperationResultingState && (lastRemainingOperation == null ? void 0 : lastRemainingOperation.resultingState)) {
1728
- scopeState = resultingStateParser(lastRemainingOperation.resultingState);
1729
- } else {
1730
- const { state } = replayOperations(
1731
- document.initialState,
1732
- documentOperations,
1733
- customReducer,
1734
- void 0,
1735
- void 0,
1736
- void 0,
1737
- void 0,
1738
- {
1739
- reuseHash: true,
1740
- reuseOperationResultingState,
1741
- operationResultingStateParser: resultingStateParser
1742
- }
1743
- );
1744
- scopeState = state[scope];
1745
- }
1746
- return {
1747
- ...document,
1748
- state: {
1749
- ...document.state,
1750
- [scope]: scopeState
1751
- },
1752
- operations: garbageCollectDocumentOperations({
1753
- ...document.operations
1754
- })
1755
- };
1756
- }
1757
- function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
1758
- const operations = [...document.operations[scope]];
1759
- const sortedOperations = sortOperations$1(operations);
1760
- sortedOperations.pop();
1761
- const documentOperations = garbageCollectDocumentOperations({
1762
- ...document.operations
1763
- });
1764
- const clearedOperations = [...documentOperations[scope]];
1765
- const diff = diffOperations(
1766
- garbageCollect(sortedOperations),
1767
- clearedOperations
1768
- );
1769
- const doc = replayOperations(
1770
- document.initialState,
1771
- documentOperations,
1772
- customReducer,
1773
- void 0,
1774
- void 0,
1775
- void 0,
1776
- void 0,
1777
- {
1778
- reuseHash: true,
1779
- reuseOperationResultingState,
1780
- operationResultingStateParser: resultingStateParser
1781
- }
1782
- );
1783
- const clipboard = sortOperations$1(
1784
- [...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")
1785
- ).reverse();
1786
- return { ...doc, clipboard };
1787
- }
1788
- function baseReducer(document, action, customReducer, dispatch, options = {}) {
1789
- const {
1790
- skip,
1791
- ignoreSkipOperations = false,
1792
- reuseHash = false,
1793
- reuseOperationResultingState = false,
1794
- operationResultingStateParser
1795
- } = options;
1796
- let _action = { ...action };
1797
- let skipValue = skip || 0;
1798
- let newDocument = { ...document };
1799
- let reuseLastOperationIndex = false;
1800
- const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
1801
- if (isUndoRedo(_action)) {
1802
- const {
1803
- skip: calculatedSkip,
1804
- action: transformedAction,
1805
- document: processedDocument,
1806
- reuseLastOperationIndex: reuseIndex
1807
- } = processUndoRedo(document, _action, skipValue);
1808
- _action = transformedAction;
1809
- skipValue = calculatedSkip;
1810
- newDocument = processedDocument;
1811
- reuseLastOperationIndex = reuseIndex;
1812
- } else {
1813
- newDocument = {
1814
- ...newDocument,
1815
- clipboard: []
1816
- };
1817
- }
1818
- if (isBaseAction(_action)) {
1819
- newDocument = _baseReducer(newDocument, _action, customReducer);
1820
- }
1821
- newDocument = updateDocument(
1822
- newDocument,
1823
- _action,
1824
- skipValue,
1825
- reuseLastOperationIndex
1826
- );
1827
- const isUndoAction = isUndo(action);
1828
- if (isUndoAction) {
1829
- const result = processUndoOperation(
1830
- newDocument,
1831
- action.scope,
1832
- customReducer
1833
- );
1834
- return result;
1835
- }
1836
- if (shouldProcessSkipOperation) {
1837
- newDocument = processSkipOperation(
1838
- newDocument,
1839
- _action,
1840
- customReducer,
1841
- skipValue,
1842
- reuseOperationResultingState,
1843
- operationResultingStateParser
1844
- );
1845
- }
1846
- newDocument = mutative.create(newDocument, (draft) => {
1847
- try {
1848
- const newState = customReducer(draft.state, _action, dispatch);
1849
- if (newState) {
1850
- mutative.unsafe(() => {
1851
- draft.state = mutative.castDraft(newState);
1852
- });
1853
- } else {
1854
- }
1855
- } catch (error) {
1856
- const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
1857
- draft.operations[_action.scope][lastOperationIndex].error = error.message;
1858
- draft.operations[_action.scope][lastOperationIndex].skip = 0;
1859
- if (shouldProcessSkipOperation) {
1860
- draft.state = mutative.castDraft({ ...document.state });
1861
- draft.operations = mutative.castDraft({
1862
- ...document.operations,
1863
- [_action.scope]: [
1864
- ...document.operations[_action.scope],
1865
- {
1866
- ...draft.operations[_action.scope][lastOperationIndex]
1867
- }
1868
- ]
1869
- });
1870
- }
1871
- }
1872
- });
1873
- if ([UNDO, REDO, PRUNE].includes(_action.type)) {
1874
- return newDocument;
1875
- }
1876
- const scope = _action.scope || "global";
1877
- const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
1878
- const lastOperation = newDocument.operations[scope].at(-1);
1879
- if (lastOperation) {
1880
- lastOperation.hash = hash2;
1881
- if (reuseOperationResultingState) {
1882
- lastOperation.resultingState = newDocument.state[scope];
1883
- }
1884
- if (!isBaseAction(_action) && _action.attachments) {
1885
- _action.attachments.forEach((attachment) => {
1886
- const { hash: hash22, ...file } = attachment;
1887
- newDocument.attachments[hash22] = {
1888
- ...file
1889
- };
1890
- });
1891
- }
1892
- }
1893
- return newDocument;
1894
- }
1895
- function mutableBaseReducer(document, action, customReducer, dispatch, options = {}) {
1896
- const {
1897
- skip,
1898
- ignoreSkipOperations = false,
1899
- reuseHash = false,
1900
- reuseOperationResultingState = false,
1901
- operationResultingStateParser
1902
- } = options;
1903
- const _action = { ...action };
1904
- const skipValue = skip || 0;
1905
- let newDocument = { ...document };
1906
- const shouldProcessSkipOperation = !ignoreSkipOperations && (skipValue > 0 || "index" in _action && _action.skip > 0);
1907
- if (isBaseAction(_action)) {
1908
- newDocument = _baseReducer(newDocument, _action, customReducer);
1909
- }
1910
- newDocument = updateDocument(newDocument, _action, skipValue);
1911
- if (shouldProcessSkipOperation) {
1912
- newDocument = processSkipOperation(
1913
- newDocument,
1914
- _action,
1915
- customReducer,
1916
- skipValue,
1917
- reuseOperationResultingState,
1918
- operationResultingStateParser
1919
- );
1920
- }
1921
- try {
1922
- const newState = customReducer(
1923
- newDocument.state,
1924
- _action,
1925
- dispatch
1926
- );
1927
- if (newState) {
1928
- newDocument.state = newState;
1929
- }
1930
- } catch (error) {
1931
- const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
1932
- newDocument.operations[_action.scope][lastOperationIndex].error = error.message;
1933
- newDocument.operations[_action.scope][lastOperationIndex].skip = 0;
1934
- if (shouldProcessSkipOperation) {
1935
- newDocument.state = { ...document.state };
1936
- newDocument.operations = {
1937
- ...document.operations,
1938
- [_action.scope]: [
1939
- ...document.operations[_action.scope],
1940
- {
1941
- ...newDocument.operations[_action.scope][lastOperationIndex]
1942
- }
1943
- ]
1944
- };
1945
- }
1946
- }
1947
- if ([UNDO, REDO, PRUNE].includes(_action.type)) {
1948
- return newDocument;
1949
- }
1950
- const scope = _action.scope || "global";
1951
- const hash2 = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash") ? _action.hash : hashDocument(newDocument, scope);
1952
- const lastOperation = newDocument.operations[scope].at(-1);
1953
- if (lastOperation) {
1954
- lastOperation.hash = hash2;
1955
- if (reuseOperationResultingState) {
1956
- lastOperation.resultingState = newDocument.state[scope];
1957
- }
1958
- if (!isBaseAction(_action) && _action.attachments) {
1959
- _action.attachments.forEach((attachment) => {
1960
- const { hash: hash22, ...file } = attachment;
1961
- newDocument.attachments[hash22] = {
1962
- ...file
1963
- };
1964
- });
1965
- }
1966
- }
1967
- return newDocument;
1968
- }
1969
- function isNoopOperation(op) {
1970
- return op.type === NOOP && op.skip !== void 0 && op.skip > 0 && op.hash !== void 0;
1971
- }
1972
- function isUndoRedo(action) {
1973
- return [UNDO, REDO].includes(action.type);
1974
- }
1975
- function isUndo(action) {
1976
- return action.type === UNDO;
1977
- }
1978
- function isBaseAction(action) {
1979
- return [SET_NAME, UNDO, REDO, PRUNE, LOAD_STATE].includes(action.type);
1980
- }
1981
- function createAction(type, input, attachments, validator, scope = "global") {
1982
- if (!type) {
1983
- throw new Error("Empty action type");
1984
- }
1985
- if (typeof type !== "string") {
1986
- throw new Error(`Invalid action type: ${JSON.stringify(type)}`);
1987
- }
1988
- const action = { type, input, scope };
1989
- if (attachments) {
1990
- action.attachments = attachments;
1991
- }
1992
- try {
1993
- validator == null ? void 0 : validator().parse(action.input);
1994
- } catch (error) {
1995
- throw new Error(`Invalid action input: ${error}`);
1996
- }
1997
- return action;
1998
- }
1999
- function createReducer(reducer, documentReducer = baseReducer) {
2000
- return (document, action, dispatch, options) => {
2001
- return documentReducer(document, action, reducer, dispatch, options);
2002
- };
2003
- }
2004
- function createUnsafeReducer(reducer, documentReducer = mutableBaseReducer) {
2005
- return (document, action, dispatch, options) => {
2006
- return documentReducer(document, action, reducer, dispatch, options);
2007
- };
2008
- }
2009
- const createExtendedState = (initialState, createState) => {
2010
- return {
2011
- name: "",
2012
- documentType: "",
2013
- revision: {
2014
- global: 0,
2015
- local: 0
2016
- },
2017
- created: (/* @__PURE__ */ new Date()).toISOString(),
2018
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
2019
- attachments: {},
2020
- ...initialState,
2021
- state: (createState == null ? void 0 : createState(initialState == null ? void 0 : initialState.state)) ?? ((initialState == null ? void 0 : initialState.state) ?? { global: {}, local: {} })
2022
- };
2023
- };
2024
- const createDocument = (initialState, createState) => {
2025
- const state = createExtendedState(
2026
- initialState,
2027
- createState
2028
- );
2029
- return {
2030
- ...state,
2031
- initialState: state,
2032
- operations: { global: [], local: [] },
2033
- clipboard: []
2034
- };
2035
- };
2036
- const hashDocument = (document, scope = "global") => {
2037
- return hash(cjsModule(document.state[scope] || ""));
2038
- };
2039
- const hashKey = (date, randomLimit = 1e3) => {
2040
- const random = Math.random() * randomLimit;
2041
- return hash(`${(date ?? /* @__PURE__ */ new Date()).toISOString()}${random}`);
2042
- };
2043
- function readOnly(value) {
2044
- return Object.freeze(value);
2045
- }
2046
- function mapSkippedOperations(operations, skippedHeadOperations) {
2047
- const ops = [...operations];
2048
- let skipped = skippedHeadOperations || 0;
2049
- let latestOpIndex = ops.length > 0 ? ops[ops.length - 1].index : 0;
2050
- const scopeOpsWithIgnore = [];
2051
- for (const operation of ops.reverse()) {
2052
- if (skipped > 0) {
2053
- const operationsDiff = latestOpIndex - operation.index;
2054
- skipped -= operationsDiff;
2055
- }
2056
- if (skipped < 0) {
2057
- throw new Error("Invalid operation index, missing operations");
2058
- }
2059
- const mappedOp = {
2060
- ignore: skipped > 0,
2061
- operation
2062
- };
2063
- const operationSkip = operation.skip > 0 ? operation.skip + 1 : 0;
2064
- if (operationSkip > 0 && operationSkip > skipped) {
2065
- const skipDiff = operationSkip - skipped;
2066
- skipped = skipped + skipDiff;
2067
- }
2068
- latestOpIndex = operation.index;
2069
- scopeOpsWithIgnore.push(mappedOp);
2070
- }
2071
- return scopeOpsWithIgnore.reverse();
2072
- }
2073
- function sortOperations(operations) {
2074
- return Object.values(operations).flatMap((array) => array).sort(
2075
- (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
2076
- );
2077
- }
2078
- function sortMappedOperations(operations) {
2079
- return Object.values(operations).flatMap((array) => array).sort(
2080
- (a, b) => new Date(a.operation.timestamp).getTime() - new Date(b.operation.timestamp).getTime()
2081
- );
2082
- }
2083
- function replayOperations(initialState, clearedOperations, reducer, dispatch, header, documentReducer = baseReducer, skipHeaderOperations2 = {}, options) {
2084
- const wrappedReducer = createReducer(reducer, documentReducer);
2085
- return replayDocument(
2086
- initialState,
2087
- clearedOperations,
2088
- wrappedReducer,
2089
- dispatch,
2090
- header,
2091
- skipHeaderOperations2,
2092
- options
2093
- );
2094
- }
2095
- function replayDocument(initialState, operations, reducer, dispatch, header, skipHeaderOperations2 = {}, options) {
2096
- const {
2097
- checkHashes = true,
2098
- reuseOperationResultingState,
2099
- operationResultingStateParser = parseResultingState
2100
- } = options || {};
2101
- let documentState = initialState;
2102
- const operationsToReplay = [];
2103
- const initialOperations = {
2104
- global: [],
2105
- local: []
2106
- };
2107
- if (reuseOperationResultingState) {
2108
- for (const [scope, scopeOperations] of Object.entries(operations)) {
2109
- const index = scopeOperations.findLastIndex((s) => !!s.resultingState);
2110
- if (index < 0) {
2111
- operationsToReplay.push(...scopeOperations);
2112
- continue;
2113
- }
2114
- const opWithState = scopeOperations[index];
2115
- try {
2116
- const scopeState = operationResultingStateParser(
2117
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
2118
- opWithState.resultingState
2119
- );
2120
- documentState = {
2121
- ...documentState,
2122
- state: {
2123
- ...documentState.state,
2124
- // TODO how to deal with attachments?
2125
- [scope]: scopeState
2126
- }
2127
- };
2128
- initialOperations[scope].push(
2129
- ...scopeOperations.slice(0, index + 1)
2130
- );
2131
- operationsToReplay.push(...scopeOperations.slice(index + 1));
2132
- } catch {
2133
- operationsToReplay.push(...scopeOperations);
2134
- }
2135
- }
2136
- } else {
2137
- operationsToReplay.push(...Object.values(operations).flat());
2138
- }
2139
- const document = createDocument(documentState);
2140
- document.initialState = initialState;
2141
- document.operations = initialOperations;
2142
- let result = document;
2143
- if (operationsToReplay.length) {
2144
- result = operationsToReplay.reduce((document2, operation) => {
2145
- const doc = reducer(document2, operation, dispatch, {
2146
- skip: operation.skip,
2147
- ignoreSkipOperations: true,
2148
- reuseHash: !checkHashes
2149
- });
2150
- return doc;
2151
- }, document);
2152
- } else {
2153
- for (const scopeOperations of Object.values(initialOperations)) {
2154
- const lastOperation = scopeOperations.at(-1);
2155
- if (lastOperation) {
2156
- result = updateHeader(result, lastOperation);
2157
- }
2158
- }
2159
- }
2160
- if (!checkHashes) {
2161
- for (const scope of Object.keys(result.state)) {
2162
- for (let i = operationsToReplay.length - 1; i >= 0; i--) {
2163
- const operation = operationsToReplay[i];
2164
- if (operation.scope !== scope) {
2165
- continue;
2166
- }
2167
- if (operation.hash !== hashDocument(result, scope)) {
2168
- throw new Error(`Hash mismatch for scope ${scope}`);
2169
- } else {
2170
- break;
2171
- }
2172
- }
2173
- }
2174
- }
2175
- const resultOperations = Object.keys(
2176
- result.operations
2177
- ).reduce(
2178
- (acc, key) => {
2179
- const scope = key;
2180
- return {
2181
- ...acc,
2182
- [scope]: [
2183
- ...result.operations[scope].map((operation, index) => {
2184
- var _a;
2185
- return {
2186
- ...operation,
2187
- timestamp: ((_a = operations[scope][index]) == null ? void 0 : _a.timestamp) ?? operation.timestamp
2188
- };
2189
- })
2190
- ]
2191
- };
2192
- },
2193
- { global: [], local: [] }
2194
- );
2195
- const lastModified = Object.values(resultOperations).reduce((acc, curr) => {
2196
- const operation = curr.at(-1);
2197
- if (operation && operation.timestamp > acc) {
2198
- acc = operation.timestamp;
2199
- }
2200
- return acc;
2201
- }, initialState.lastModified);
2202
- return { ...result, operations: resultOperations, lastModified };
2203
- }
2204
- function isSameDocument(documentA, documentB) {
2205
- return cjsModule(documentA) === cjsModule(documentB);
2206
- }
2207
- function parseResultingState(state) {
2208
- const stateType = typeof state;
2209
- if (stateType === "string") {
2210
- return JSON.parse(state);
2211
- } else if (stateType === "object") {
2212
- return state;
2213
- } else {
2214
- throw new Error(`Providing resulting state is of type: ${stateType}`);
2215
- }
2216
- }
2217
- const setName = (name) => createAction(
2218
- "SET_NAME",
2219
- name,
2220
- void 0,
2221
- SetNameActionInputSchema,
2222
- void 0
2223
- );
2224
- const undo = (skip = 1, scope = "global") => createAction(
2225
- "UNDO",
2226
- skip,
2227
- void 0,
2228
- UndoActionInputSchema,
2229
- scope
2230
- );
2231
- const redo = (count = 1, scope = "global") => createAction(
2232
- "REDO",
2233
- count,
2234
- void 0,
2235
- RedoActionInputSchema,
2236
- scope
2237
- );
2238
- const prune = (start, end, scope = "global") => createAction(
2239
- "PRUNE",
2240
- { start, end },
2241
- void 0,
2242
- PruneActionInputSchema,
2243
- scope
2244
- );
2245
- const loadState = (state, operations) => createAction(
2246
- "LOAD_STATE",
2247
- { state, operations },
2248
- void 0,
2249
- LoadStateActionInputSchema
2250
- );
2251
- const noop = (scope = "global") => createAction("NOOP", {}, void 0, void 0, scope);
2252
- const BaseActions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2253
- __proto__: null,
2254
- loadState,
2255
- noop,
2256
- prune,
2257
- redo,
2258
- setName,
2259
- undo
2260
- }, Symbol.toStringTag, { value: "Module" }));
2261
- class BaseDocument {
2262
- /**
2263
- * Constructs a BaseDocument instance with an initial state.
2264
- * @param reducer - The reducer function that updates the state.
2265
- * @param document - The initial state of the document.
2266
- */
2267
- constructor(reducer, document, signalDispatch) {
2268
- __publicField(this, "_document");
2269
- __publicField(this, "_reducer");
2270
- __publicField(this, "_signalDispatch");
2271
- this._reducer = reducer;
2272
- this._document = document;
2273
- this._signalDispatch = signalDispatch;
2274
- }
2275
- /**
2276
- * Dispatches an action to update the state of the document.
2277
- * @param action - The action to dispatch.
2278
- * @returns The Document instance.
2279
- */
2280
- dispatch(action, options) {
2281
- this._document = this._reducer(
2282
- this._document,
2283
- action,
2284
- this._signalDispatch,
2285
- options
2286
- );
2287
- return this;
2288
- }
2289
- /**
2290
- * Saves the state of the document to a file.
2291
- * @param path - The file path where the state should be saved.
2292
- * @param extension - The file extension to use when saving the state.
2293
- * @returns The file path where the state was saved.
2294
- */
2295
- saveToFile(path2, extension, name) {
2296
- return saveToFile(this._document, path2, extension, name);
2297
- }
2298
- /**
2299
- * Loads the state of the document from a file.
2300
- * @param path - The file path where the state is stored.
2301
- */
2302
- async loadFromFile(path2) {
2303
- this._document = await loadFromFile(path2, this._reducer);
2304
- }
2305
- /**
2306
- * Loads the state of the document from a file and returns it.
2307
- * @param path - The file path where the state is stored.
2308
- * @param reducer - The reducer function that updates the state.
2309
- * @returns The state of the document.
2310
- */
2311
- static async stateFromFile(path2, reducer) {
2312
- const state = await loadFromFile(path2, reducer);
2313
- return state;
2314
- }
2315
- /**
2316
- * Gets the current state of the document.
2317
- */
2318
- get state() {
2319
- return readOnly(this._document.state);
2320
- }
2321
- /**
2322
- * Gets the list of operations performed on the document.
2323
- */
2324
- get operations() {
2325
- return readOnly(this._document.operations);
2326
- }
2327
- /**
2328
- * Gets the name of the document.
2329
- */
2330
- get name() {
2331
- return this._document.name;
2332
- }
2333
- /**
2334
- * Gets the type of document.
2335
- */
2336
- get documentType() {
2337
- return this._document.documentType;
2338
- }
2339
- /**
2340
- * Gets the timestamp of the date the document was created.
2341
- */
2342
- get created() {
2343
- return this._document.created;
2344
- }
2345
- /**
2346
- * Gets the timestamp of the date the document was last modified.
2347
- */
2348
- get lastModified() {
2349
- return this._document.lastModified;
2350
- }
2351
- /**
2352
- * Gets the global revision number of the document.
2353
- */
2354
- get revision() {
2355
- return this._document.revision.global;
2356
- }
2357
- getRevision(scope) {
2358
- return this._document.revision[scope];
2359
- }
2360
- /**
2361
- * Gets the initial state of the document.
2362
- */
2363
- get initialState() {
2364
- return readOnly(this._document.initialState);
2365
- }
2366
- /**
2367
- * Returns the current document as an object
2368
- */
2369
- toDocument() {
2370
- return readOnly(this._document);
2371
- }
2372
- /**
2373
- * Gets the attachment associated with the given key.
2374
- * @param attachment - The key of the attachment to retrieve.
2375
- */
2376
- getAttachment(attachment) {
2377
- return this._document.attachments[attachment];
2378
- }
2379
- /**
2380
- * Sets the name of the document.
2381
- * @param name - The new name of the document.
2382
- */
2383
- setName(name) {
2384
- this.dispatch(setName(name));
2385
- return this;
2386
- }
2387
- /**
2388
- * Reverts a number of actions from the document.
2389
- * @param count - The number of actions to revert.
2390
- */
2391
- undo(count) {
2392
- this.dispatch(undo(count));
2393
- return this;
2394
- }
2395
- /**
2396
- * Reapplies a number of actions to the document.
2397
- * @param count - The number of actions to reapply.
2398
- */
2399
- redo(count) {
2400
- this.dispatch(redo(count));
2401
- return this;
2402
- }
2403
- /**
2404
- * Removes a range of operations from the document.
2405
- * @param start - The starting index of the range to remove.
2406
- * @param end - The ending index of the range to remove.
2407
- */
2408
- prune(start, end) {
2409
- this.dispatch(prune(start, end));
2410
- return this;
2411
- }
2412
- /**
2413
- * Loads a document state and a set of operations.
2414
- * @param state - The state to load.
2415
- * @param operations - The operations to apply to the document.
2416
- */
2417
- loadState(state, operations) {
2418
- this.dispatch(loadState(state, operations));
2419
- return this;
2420
- }
2421
- }
2422
- function applyMixins(derivedCtor, constructors) {
2423
- constructors.forEach((baseCtor) => {
2424
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
2425
- Object.defineProperty(
2426
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2427
- derivedCtor.prototype,
2428
- name,
2429
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
2430
- Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || /* @__PURE__ */ Object.create(null)
2431
- );
2432
- });
2433
- });
2434
- }
2435
- exports.BaseActions = BaseActions;
2436
- exports.BaseDocument = BaseDocument;
2437
- exports.ab2hex = ab2hex;
2438
- exports.applyMixins = applyMixins;
2439
- exports.baseReducer = baseReducer;
2440
- exports.buildOperationSignature = buildOperationSignature;
2441
- exports.buildOperationSignatureMessage = buildOperationSignatureMessage;
2442
- exports.buildOperationSignatureParams = buildOperationSignatureParams;
2443
- exports.buildSignedOperation = buildSignedOperation;
2444
- exports.createAction = createAction;
2445
- exports.createDocument = createDocument;
2446
- exports.createExtendedState = createExtendedState;
2447
- exports.createReducer = createReducer;
2448
- exports.createUnsafeReducer = createUnsafeReducer;
2449
- exports.createZip = createZip;
2450
- exports.documentHelpers = documentHelpers;
2451
- exports.getLocalFile = getLocalFile;
2452
- exports.getRemoteFile = getRemoteFile;
2453
- exports.getUnixTimestamp = getUnixTimestamp;
2454
- exports.hashDocument = hashDocument;
2455
- exports.hashKey = hashKey;
2456
- exports.hex2ab = hex2ab;
2457
- exports.isBaseAction = isBaseAction;
2458
- exports.isNoopOperation = isNoopOperation;
2459
- exports.isSameDocument = isSameDocument;
2460
- exports.isUndo = isUndo;
2461
- exports.isUndoRedo = isUndoRedo;
2462
- exports.loadFromFile = loadFromFile;
2463
- exports.loadFromInput = loadFromInput;
2464
- exports.mapSkippedOperations = mapSkippedOperations;
2465
- exports.mutableBaseReducer = mutableBaseReducer;
2466
- exports.parseResultingState = parseResultingState;
2467
- exports.processUndoRedo = processUndoRedo;
2468
- exports.readOnly = readOnly;
2469
- exports.replayDocument = replayDocument;
2470
- exports.replayOperations = replayOperations;
2471
- exports.saveToFile = saveToFile;
2472
- exports.saveToFileHandle = saveToFileHandle;
2473
- exports.sortMappedOperations = sortMappedOperations;
2474
- exports.sortOperations = sortOperations;
2475
- exports.updateDocument = updateDocument;
2476
- exports.updateHeader = updateHeader;
2477
- exports.validateOperations = validateOperations;
2478
- exports.verifyOperationSignature = verifyOperationSignature;
2479
- exports.zod = zod;
2480
- //# sourceMappingURL=object-ByNZ3G_j.js.map