document-model 4.1.0-dev.1 → 4.1.0-dev.100

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 (440) hide show
  1. package/README.md +24 -24
  2. package/dist/src/core/actions.d.ts +79 -0
  3. package/dist/src/core/actions.d.ts.map +1 -0
  4. package/dist/src/core/actions.js +183 -0
  5. package/dist/src/core/actions.js.map +1 -0
  6. package/dist/src/core/crypto.d.ts +17 -0
  7. package/dist/src/core/crypto.d.ts.map +1 -0
  8. package/dist/src/core/crypto.js +87 -0
  9. package/dist/src/core/crypto.js.map +1 -0
  10. package/dist/src/core/documents.d.ts +128 -0
  11. package/dist/src/core/documents.d.ts.map +1 -0
  12. package/dist/src/{document/utils/document-helpers.js → core/documents.js} +364 -26
  13. package/dist/src/core/documents.js.map +1 -0
  14. package/dist/src/core/errors.d.ts +21 -0
  15. package/dist/src/core/errors.d.ts.map +1 -0
  16. package/dist/src/core/errors.js +47 -0
  17. package/dist/src/core/errors.js.map +1 -0
  18. package/dist/src/core/files.d.ts +14 -0
  19. package/dist/src/core/files.d.ts.map +1 -0
  20. package/dist/src/core/files.js +74 -0
  21. package/dist/src/core/files.js.map +1 -0
  22. package/dist/src/{document/utils → core}/header.d.ts +3 -35
  23. package/dist/src/core/header.d.ts.map +1 -0
  24. package/dist/src/{document/utils → core}/header.js +6 -19
  25. package/dist/src/core/header.js.map +1 -0
  26. package/dist/src/core/index.d.ts +12 -0
  27. package/dist/src/core/index.d.ts.map +1 -0
  28. package/dist/src/core/index.js +12 -0
  29. package/dist/src/core/index.js.map +1 -0
  30. package/dist/src/{document/utils/file.d.ts → core/node.d.ts} +40 -29
  31. package/dist/src/core/node.d.ts.map +1 -0
  32. package/dist/src/core/node.js +149 -0
  33. package/dist/src/core/node.js.map +1 -0
  34. package/dist/src/core/operations.d.ts +32 -0
  35. package/dist/src/core/operations.d.ts.map +1 -0
  36. package/dist/src/{document/actions → core}/operations.js +11 -59
  37. package/dist/src/core/operations.js.map +1 -0
  38. package/dist/src/core/ph-types.d.ts +259 -0
  39. package/dist/src/core/ph-types.d.ts.map +1 -0
  40. package/dist/src/core/ph-types.js +15 -0
  41. package/dist/src/core/ph-types.js.map +1 -0
  42. package/dist/src/core/reducer.d.ts +61 -0
  43. package/dist/src/core/reducer.d.ts.map +1 -0
  44. package/dist/src/core/reducer.js +416 -0
  45. package/dist/src/core/reducer.js.map +1 -0
  46. package/dist/src/{document/schema/zod.d.ts → core/schemas.d.ts} +50 -24
  47. package/dist/src/core/schemas.d.ts.map +1 -0
  48. package/dist/src/{document/schema/zod.js → core/schemas.js} +24 -27
  49. package/dist/src/core/schemas.js.map +1 -0
  50. package/dist/src/core/state.d.ts +26 -0
  51. package/dist/src/core/state.d.ts.map +1 -0
  52. package/dist/src/core/state.js +56 -0
  53. package/dist/src/core/state.js.map +1 -0
  54. package/dist/src/core/types.d.ts +500 -0
  55. package/dist/src/core/types.d.ts.map +1 -0
  56. package/dist/src/{document → core}/types.js.map +1 -1
  57. package/dist/src/core/validation.d.ts +4 -0
  58. package/dist/src/core/validation.d.ts.map +1 -0
  59. package/dist/src/{document/utils → core}/validation.js +6 -2
  60. package/dist/src/core/validation.js.map +1 -0
  61. package/dist/src/document-model/actions.d.ts +158 -0
  62. package/dist/src/document-model/actions.d.ts.map +1 -0
  63. package/dist/src/document-model/actions.js +109 -0
  64. package/dist/src/document-model/actions.js.map +1 -0
  65. package/dist/src/document-model/constants.d.ts +7 -0
  66. package/dist/src/document-model/constants.d.ts.map +1 -0
  67. package/dist/src/document-model/{gen/document-model.js → constants.js} +171 -139
  68. package/dist/src/document-model/constants.js.map +1 -0
  69. package/dist/src/document-model/files.d.ts +5 -0
  70. package/dist/src/document-model/files.d.ts.map +1 -0
  71. package/dist/src/document-model/files.js +9 -0
  72. package/dist/src/document-model/files.js.map +1 -0
  73. package/dist/src/document-model/index.d.ts +9 -0
  74. package/dist/src/document-model/index.d.ts.map +1 -0
  75. package/dist/src/document-model/index.js +9 -0
  76. package/dist/src/document-model/index.js.map +1 -0
  77. package/dist/src/document-model/module.d.ts +1 -1
  78. package/dist/src/document-model/module.d.ts.map +1 -1
  79. package/dist/src/document-model/module.js +17 -10
  80. package/dist/src/document-model/module.js.map +1 -1
  81. package/dist/src/document-model/reducers.d.ts +11 -0
  82. package/dist/src/document-model/reducers.d.ts.map +1 -0
  83. package/dist/src/document-model/reducers.js +588 -0
  84. package/dist/src/document-model/reducers.js.map +1 -0
  85. package/dist/src/document-model/schemas.d.ts +449 -0
  86. package/dist/src/document-model/schemas.d.ts.map +1 -0
  87. package/dist/src/document-model/{gen/schema/zod.js → schemas.js} +9 -15
  88. package/dist/src/document-model/schemas.js.map +1 -0
  89. package/dist/src/document-model/state.d.ts +11 -0
  90. package/dist/src/document-model/state.d.ts.map +1 -0
  91. package/dist/src/document-model/state.js +61 -0
  92. package/dist/src/document-model/state.js.map +1 -0
  93. package/dist/src/document-model/types.d.ts +671 -3
  94. package/dist/src/document-model/types.d.ts.map +1 -1
  95. package/dist/src/document-model/validation.d.ts +7 -0
  96. package/dist/src/document-model/validation.d.ts.map +1 -0
  97. package/dist/src/document-model/{custom/utils.js → validation.js} +1 -1
  98. package/dist/src/document-model/validation.js.map +1 -0
  99. package/dist/src/index.d.ts +5 -0
  100. package/dist/src/index.d.ts.map +1 -0
  101. package/dist/src/index.js +2 -0
  102. package/dist/src/index.js.map +1 -0
  103. package/dist/test/document/crypto.test.js +39 -61
  104. package/dist/test/document/crypto.test.js.map +1 -1
  105. package/dist/test/document/event-vs-command.test.js +81 -51
  106. package/dist/test/document/event-vs-command.test.js.map +1 -1
  107. package/dist/test/document/local.test.js +27 -45
  108. package/dist/test/document/local.test.js.map +1 -1
  109. package/dist/test/document/operation-id.test.js +4 -7
  110. package/dist/test/document/operation-id.test.js.map +1 -1
  111. package/dist/test/document/prune.test.js +23 -36
  112. package/dist/test/document/prune.test.js.map +1 -1
  113. package/dist/test/document/reducer.test.js +101 -81
  114. package/dist/test/document/reducer.test.js.map +1 -1
  115. package/dist/test/document/skip-operations.test.js +67 -87
  116. package/dist/test/document/skip-operations.test.js.map +1 -1
  117. package/dist/test/document/undo-redo.test.js +64 -40
  118. package/dist/test/document/undo-redo.test.js.map +1 -1
  119. package/dist/test/document/utils.test.js +51 -41
  120. package/dist/test/document/utils.test.js.map +1 -1
  121. package/dist/test/document-helpers/addUndo.test.js +2 -2
  122. package/dist/test/document-helpers/addUndo.test.js.map +1 -1
  123. package/dist/test/document-helpers/attachBranch.test.js +21 -21
  124. package/dist/test/document-helpers/attachBranch.test.js.map +1 -1
  125. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js +1 -1
  126. package/dist/test/document-helpers/checkCleanedOperationsIntegrity.test.js.map +1 -1
  127. package/dist/test/document-helpers/conflictResolution.test.js +11 -11
  128. package/dist/test/document-helpers/conflictResolution.test.js.map +1 -1
  129. package/dist/test/document-helpers/filterDuplicatedOperations.test.js +1 -1
  130. package/dist/test/document-helpers/filterDuplicatedOperations.test.js.map +1 -1
  131. package/dist/test/document-helpers/garbageCollect.test.js +1 -1
  132. package/dist/test/document-helpers/garbageCollect.test.js.map +1 -1
  133. package/dist/test/document-helpers/groupOperationsByScope.test.js +71 -71
  134. package/dist/test/document-helpers/groupOperationsByScope.test.js.map +1 -1
  135. package/dist/test/document-helpers/merge.test.js +126 -126
  136. package/dist/test/document-helpers/merge.test.js.map +1 -1
  137. package/dist/test/document-helpers/nextSkipNumber.test.js +1 -1
  138. package/dist/test/document-helpers/nextSkipNumber.test.js.map +1 -1
  139. package/dist/test/document-helpers/prepareOperations.test.js +1 -1
  140. package/dist/test/document-helpers/prepareOperations.test.js.map +1 -1
  141. package/dist/test/document-helpers/removeExistingOperations.test.js +38 -26
  142. package/dist/test/document-helpers/removeExistingOperations.test.js.map +1 -1
  143. package/dist/test/document-helpers/reshuffleByTimestamp.test.js +16 -16
  144. package/dist/test/document-helpers/reshuffleByTimestamp.test.js.map +1 -1
  145. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js +22 -22
  146. package/dist/test/document-helpers/reshuffleByTimestampAndIndex.test.js.map +1 -1
  147. package/dist/test/document-helpers/skipHeaderOperations.test.js +34 -41
  148. package/dist/test/document-helpers/skipHeaderOperations.test.js.map +1 -1
  149. package/dist/test/document-helpers/sortOperations.test.js +1 -1
  150. package/dist/test/document-helpers/sortOperations.test.js.map +1 -1
  151. package/dist/test/document-helpers/split.test.js +3 -3
  152. package/dist/test/document-helpers/split.test.js.map +1 -1
  153. package/dist/test/document-helpers/utils.d.ts +2 -1
  154. package/dist/test/document-helpers/utils.d.ts.map +1 -1
  155. package/dist/test/document-helpers/utils.js +13 -8
  156. package/dist/test/document-helpers/utils.js.map +1 -1
  157. package/dist/test/document-model/replay.test.js +21 -25
  158. package/dist/test/document-model/replay.test.js.map +1 -1
  159. package/dist/test/document-model/skip-operations.test.js +93 -96
  160. package/dist/test/document-model/skip-operations.test.js.map +1 -1
  161. package/dist/test/document-model/validation.test.js +10 -13
  162. package/dist/test/document-model/validation.test.js.map +1 -1
  163. package/dist/test/document-model/zip.test.js +20 -21
  164. package/dist/test/document-model/zip.test.js.map +1 -1
  165. package/dist/test/helpers.d.ts +59 -13
  166. package/dist/test/helpers.d.ts.map +1 -1
  167. package/dist/test/helpers.js +58 -11
  168. package/dist/test/helpers.js.map +1 -1
  169. package/dist/test/index.d.ts +4 -0
  170. package/dist/test/index.d.ts.map +1 -0
  171. package/dist/test/index.js +3 -0
  172. package/dist/test/index.js.map +1 -0
  173. package/dist/test/types.d.ts +6 -0
  174. package/dist/test/types.d.ts.map +1 -0
  175. package/dist/{src/document/schema → test}/types.js.map +1 -1
  176. package/dist/tsconfig.tsbuildinfo +1 -1
  177. package/dist/vitest.config.d.ts +1 -1
  178. package/dist/vitest.config.d.ts.map +1 -1
  179. package/dist/vitest.config.js +2 -8
  180. package/dist/vitest.config.js.map +1 -1
  181. package/package.json +27 -21
  182. package/dist/index.d.ts +0 -20
  183. package/dist/index.d.ts.map +0 -1
  184. package/dist/index.js +0 -14
  185. package/dist/index.js.map +0 -1
  186. package/dist/src/document/actions/creators.d.ts +0 -51
  187. package/dist/src/document/actions/creators.d.ts.map +0 -1
  188. package/dist/src/document/actions/creators.js +0 -57
  189. package/dist/src/document/actions/creators.js.map +0 -1
  190. package/dist/src/document/actions/operations.d.ts +0 -36
  191. package/dist/src/document/actions/operations.d.ts.map +0 -1
  192. package/dist/src/document/actions/operations.js.map +0 -1
  193. package/dist/src/document/actions/types.d.ts +0 -16
  194. package/dist/src/document/actions/types.d.ts.map +0 -1
  195. package/dist/src/document/actions/types.js +0 -7
  196. package/dist/src/document/actions/types.js.map +0 -1
  197. package/dist/src/document/object.d.ts +0 -124
  198. package/dist/src/document/object.d.ts.map +0 -1
  199. package/dist/src/document/object.js +0 -183
  200. package/dist/src/document/object.js.map +0 -1
  201. package/dist/src/document/ph-types.d.ts +0 -68
  202. package/dist/src/document/ph-types.d.ts.map +0 -1
  203. package/dist/src/document/ph-types.js +0 -2
  204. package/dist/src/document/ph-types.js.map +0 -1
  205. package/dist/src/document/reducer.d.ts +0 -49
  206. package/dist/src/document/reducer.d.ts.map +0 -1
  207. package/dist/src/document/reducer.js +0 -346
  208. package/dist/src/document/reducer.js.map +0 -1
  209. package/dist/src/document/schema/types.d.ts +0 -177
  210. package/dist/src/document/schema/types.d.ts.map +0 -1
  211. package/dist/src/document/schema/types.js +0 -2
  212. package/dist/src/document/schema/zod.d.ts.map +0 -1
  213. package/dist/src/document/schema/zod.js.map +0 -1
  214. package/dist/src/document/signal.d.ts +0 -36
  215. package/dist/src/document/signal.d.ts.map +0 -1
  216. package/dist/src/document/signal.js +0 -2
  217. package/dist/src/document/signal.js.map +0 -1
  218. package/dist/src/document/types.d.ts +0 -336
  219. package/dist/src/document/types.d.ts.map +0 -1
  220. package/dist/src/document/types.js +0 -2
  221. package/dist/src/document/utils/base.d.ts +0 -88
  222. package/dist/src/document/utils/base.d.ts.map +0 -1
  223. package/dist/src/document/utils/base.js +0 -335
  224. package/dist/src/document/utils/base.js.map +0 -1
  225. package/dist/src/document/utils/browser.d.ts +0 -18
  226. package/dist/src/document/utils/browser.d.ts.map +0 -1
  227. package/dist/src/document/utils/browser.js +0 -54
  228. package/dist/src/document/utils/browser.js.map +0 -1
  229. package/dist/src/document/utils/crypto.d.ts +0 -11
  230. package/dist/src/document/utils/crypto.d.ts.map +0 -1
  231. package/dist/src/document/utils/crypto.js +0 -80
  232. package/dist/src/document/utils/crypto.js.map +0 -1
  233. package/dist/src/document/utils/document-helpers.d.ts +0 -78
  234. package/dist/src/document/utils/document-helpers.d.ts.map +0 -1
  235. package/dist/src/document/utils/document-helpers.js.map +0 -1
  236. package/dist/src/document/utils/errors.d.ts +0 -10
  237. package/dist/src/document/utils/errors.d.ts.map +0 -1
  238. package/dist/src/document/utils/errors.js +0 -19
  239. package/dist/src/document/utils/errors.js.map +0 -1
  240. package/dist/src/document/utils/file.d.ts.map +0 -1
  241. package/dist/src/document/utils/file.js +0 -152
  242. package/dist/src/document/utils/file.js.map +0 -1
  243. package/dist/src/document/utils/header.d.ts.map +0 -1
  244. package/dist/src/document/utils/header.js.map +0 -1
  245. package/dist/src/document/utils/node.d.ts +0 -18
  246. package/dist/src/document/utils/node.d.ts.map +0 -1
  247. package/dist/src/document/utils/node.js +0 -62
  248. package/dist/src/document/utils/node.js.map +0 -1
  249. package/dist/src/document/utils/validation.d.ts +0 -3
  250. package/dist/src/document/utils/validation.d.ts.map +0 -1
  251. package/dist/src/document/utils/validation.js.map +0 -1
  252. package/dist/src/document-model/custom/reducers/header.d.ts +0 -3
  253. package/dist/src/document-model/custom/reducers/header.d.ts.map +0 -1
  254. package/dist/src/document-model/custom/reducers/header.js +0 -23
  255. package/dist/src/document-model/custom/reducers/header.js.map +0 -1
  256. package/dist/src/document-model/custom/reducers/module.d.ts +0 -3
  257. package/dist/src/document-model/custom/reducers/module.d.ts.map +0 -1
  258. package/dist/src/document-model/custom/reducers/module.js +0 -41
  259. package/dist/src/document-model/custom/reducers/module.js.map +0 -1
  260. package/dist/src/document-model/custom/reducers/operation-error.d.ts +0 -3
  261. package/dist/src/document-model/custom/reducers/operation-error.d.ts.map +0 -1
  262. package/dist/src/document-model/custom/reducers/operation-error.js +0 -94
  263. package/dist/src/document-model/custom/reducers/operation-error.js.map +0 -1
  264. package/dist/src/document-model/custom/reducers/operation-example.d.ts +0 -3
  265. package/dist/src/document-model/custom/reducers/operation-example.d.ts.map +0 -1
  266. package/dist/src/document-model/custom/reducers/operation-example.js +0 -53
  267. package/dist/src/document-model/custom/reducers/operation-example.js.map +0 -1
  268. package/dist/src/document-model/custom/reducers/operation.d.ts +0 -3
  269. package/dist/src/document-model/custom/reducers/operation.d.ts.map +0 -1
  270. package/dist/src/document-model/custom/reducers/operation.js +0 -125
  271. package/dist/src/document-model/custom/reducers/operation.js.map +0 -1
  272. package/dist/src/document-model/custom/reducers/state.d.ts +0 -3
  273. package/dist/src/document-model/custom/reducers/state.d.ts.map +0 -1
  274. package/dist/src/document-model/custom/reducers/state.js +0 -71
  275. package/dist/src/document-model/custom/reducers/state.js.map +0 -1
  276. package/dist/src/document-model/custom/reducers/versioning.d.ts +0 -8
  277. package/dist/src/document-model/custom/reducers/versioning.d.ts.map +0 -1
  278. package/dist/src/document-model/custom/reducers/versioning.js +0 -23
  279. package/dist/src/document-model/custom/reducers/versioning.js.map +0 -1
  280. package/dist/src/document-model/custom/utils.d.ts +0 -8
  281. package/dist/src/document-model/custom/utils.d.ts.map +0 -1
  282. package/dist/src/document-model/custom/utils.js.map +0 -1
  283. package/dist/src/document-model/gen/actions.d.ts +0 -16
  284. package/dist/src/document-model/gen/actions.d.ts.map +0 -1
  285. package/dist/src/document-model/gen/actions.js +0 -8
  286. package/dist/src/document-model/gen/actions.js.map +0 -1
  287. package/dist/src/document-model/gen/constants.d.ts +0 -7
  288. package/dist/src/document-model/gen/constants.d.ts.map +0 -1
  289. package/dist/src/document-model/gen/constants.js +0 -34
  290. package/dist/src/document-model/gen/constants.js.map +0 -1
  291. package/dist/src/document-model/gen/creators.d.ts +0 -8
  292. package/dist/src/document-model/gen/creators.d.ts.map +0 -1
  293. package/dist/src/document-model/gen/creators.js +0 -8
  294. package/dist/src/document-model/gen/creators.js.map +0 -1
  295. package/dist/src/document-model/gen/document-model.d.ts +0 -3
  296. package/dist/src/document-model/gen/document-model.d.ts.map +0 -1
  297. package/dist/src/document-model/gen/document-model.js.map +0 -1
  298. package/dist/src/document-model/gen/header/actions.d.ts +0 -10
  299. package/dist/src/document-model/gen/header/actions.d.ts.map +0 -1
  300. package/dist/src/document-model/gen/header/actions.js +0 -2
  301. package/dist/src/document-model/gen/header/actions.js.map +0 -1
  302. package/dist/src/document-model/gen/header/creators.d.ts +0 -9
  303. package/dist/src/document-model/gen/header/creators.d.ts.map +0 -1
  304. package/dist/src/document-model/gen/header/creators.js +0 -10
  305. package/dist/src/document-model/gen/header/creators.js.map +0 -1
  306. package/dist/src/document-model/gen/header/object.d.ts +0 -13
  307. package/dist/src/document-model/gen/header/object.d.ts.map +0 -1
  308. package/dist/src/document-model/gen/header/object.js +0 -23
  309. package/dist/src/document-model/gen/header/object.js.map +0 -1
  310. package/dist/src/document-model/gen/header/operations.d.ts +0 -11
  311. package/dist/src/document-model/gen/header/operations.d.ts.map +0 -1
  312. package/dist/src/document-model/gen/header/operations.js +0 -2
  313. package/dist/src/document-model/gen/header/operations.js.map +0 -1
  314. package/dist/src/document-model/gen/module/actions.d.ts +0 -9
  315. package/dist/src/document-model/gen/module/actions.d.ts.map +0 -1
  316. package/dist/src/document-model/gen/module/actions.js +0 -2
  317. package/dist/src/document-model/gen/module/actions.js.map +0 -1
  318. package/dist/src/document-model/gen/module/creators.d.ts +0 -8
  319. package/dist/src/document-model/gen/module/creators.d.ts.map +0 -1
  320. package/dist/src/document-model/gen/module/creators.js +0 -9
  321. package/dist/src/document-model/gen/module/creators.js.map +0 -1
  322. package/dist/src/document-model/gen/module/object.d.ts +0 -12
  323. package/dist/src/document-model/gen/module/object.d.ts.map +0 -1
  324. package/dist/src/document-model/gen/module/object.js +0 -20
  325. package/dist/src/document-model/gen/module/object.js.map +0 -1
  326. package/dist/src/document-model/gen/module/operations.d.ts +0 -10
  327. package/dist/src/document-model/gen/module/operations.d.ts.map +0 -1
  328. package/dist/src/document-model/gen/module/operations.js +0 -2
  329. package/dist/src/document-model/gen/module/operations.js.map +0 -1
  330. package/dist/src/document-model/gen/object.d.ts +0 -29
  331. package/dist/src/document-model/gen/object.d.ts.map +0 -1
  332. package/dist/src/document-model/gen/object.js +0 -46
  333. package/dist/src/document-model/gen/object.js.map +0 -1
  334. package/dist/src/document-model/gen/operation/actions.d.ts +0 -14
  335. package/dist/src/document-model/gen/operation/actions.d.ts.map +0 -1
  336. package/dist/src/document-model/gen/operation/actions.js +0 -2
  337. package/dist/src/document-model/gen/operation/actions.js.map +0 -1
  338. package/dist/src/document-model/gen/operation/creators.d.ts +0 -13
  339. package/dist/src/document-model/gen/operation/creators.d.ts.map +0 -1
  340. package/dist/src/document-model/gen/operation/creators.js +0 -20
  341. package/dist/src/document-model/gen/operation/creators.js.map +0 -1
  342. package/dist/src/document-model/gen/operation/object.d.ts +0 -18
  343. package/dist/src/document-model/gen/operation/object.d.ts.map +0 -1
  344. package/dist/src/document-model/gen/operation/object.js +0 -35
  345. package/dist/src/document-model/gen/operation/object.js.map +0 -1
  346. package/dist/src/document-model/gen/operation/operations.d.ts +0 -15
  347. package/dist/src/document-model/gen/operation/operations.d.ts.map +0 -1
  348. package/dist/src/document-model/gen/operation/operations.js +0 -2
  349. package/dist/src/document-model/gen/operation/operations.js.map +0 -1
  350. package/dist/src/document-model/gen/operation-error/actions.d.ts +0 -11
  351. package/dist/src/document-model/gen/operation-error/actions.d.ts.map +0 -1
  352. package/dist/src/document-model/gen/operation-error/actions.js +0 -2
  353. package/dist/src/document-model/gen/operation-error/actions.js.map +0 -1
  354. package/dist/src/document-model/gen/operation-error/creators.d.ts +0 -10
  355. package/dist/src/document-model/gen/operation-error/creators.d.ts.map +0 -1
  356. package/dist/src/document-model/gen/operation-error/creators.js +0 -17
  357. package/dist/src/document-model/gen/operation-error/creators.js.map +0 -1
  358. package/dist/src/document-model/gen/operation-error/object.d.ts +0 -15
  359. package/dist/src/document-model/gen/operation-error/object.d.ts.map +0 -1
  360. package/dist/src/document-model/gen/operation-error/object.js +0 -26
  361. package/dist/src/document-model/gen/operation-error/object.js.map +0 -1
  362. package/dist/src/document-model/gen/operation-error/operations.d.ts +0 -12
  363. package/dist/src/document-model/gen/operation-error/operations.d.ts.map +0 -1
  364. package/dist/src/document-model/gen/operation-error/operations.js +0 -2
  365. package/dist/src/document-model/gen/operation-error/operations.js.map +0 -1
  366. package/dist/src/document-model/gen/operation-example/actions.d.ts +0 -8
  367. package/dist/src/document-model/gen/operation-example/actions.d.ts.map +0 -1
  368. package/dist/src/document-model/gen/operation-example/actions.js +0 -2
  369. package/dist/src/document-model/gen/operation-example/actions.js.map +0 -1
  370. package/dist/src/document-model/gen/operation-example/creators.d.ts +0 -7
  371. package/dist/src/document-model/gen/operation-example/creators.d.ts.map +0 -1
  372. package/dist/src/document-model/gen/operation-example/creators.js +0 -14
  373. package/dist/src/document-model/gen/operation-example/creators.js.map +0 -1
  374. package/dist/src/document-model/gen/operation-example/object.d.ts +0 -12
  375. package/dist/src/document-model/gen/operation-example/object.d.ts.map +0 -1
  376. package/dist/src/document-model/gen/operation-example/object.js +0 -17
  377. package/dist/src/document-model/gen/operation-example/object.js.map +0 -1
  378. package/dist/src/document-model/gen/operation-example/operations.d.ts +0 -9
  379. package/dist/src/document-model/gen/operation-example/operations.d.ts.map +0 -1
  380. package/dist/src/document-model/gen/operation-example/operations.js +0 -2
  381. package/dist/src/document-model/gen/operation-example/operations.js.map +0 -1
  382. package/dist/src/document-model/gen/reducer.d.ts +0 -5
  383. package/dist/src/document-model/gen/reducer.d.ts.map +0 -1
  384. package/dist/src/document-model/gen/reducer.js +0 -193
  385. package/dist/src/document-model/gen/reducer.js.map +0 -1
  386. package/dist/src/document-model/gen/schema/types.d.ts +0 -458
  387. package/dist/src/document-model/gen/schema/types.d.ts.map +0 -1
  388. package/dist/src/document-model/gen/schema/types.js.map +0 -1
  389. package/dist/src/document-model/gen/schema/zod.d.ts +0 -454
  390. package/dist/src/document-model/gen/schema/zod.d.ts.map +0 -1
  391. package/dist/src/document-model/gen/schema/zod.js.map +0 -1
  392. package/dist/src/document-model/gen/state/actions.d.ts +0 -10
  393. package/dist/src/document-model/gen/state/actions.d.ts.map +0 -1
  394. package/dist/src/document-model/gen/state/actions.js +0 -2
  395. package/dist/src/document-model/gen/state/actions.js.map +0 -1
  396. package/dist/src/document-model/gen/state/creators.d.ts +0 -9
  397. package/dist/src/document-model/gen/state/creators.d.ts.map +0 -1
  398. package/dist/src/document-model/gen/state/creators.js +0 -10
  399. package/dist/src/document-model/gen/state/creators.js.map +0 -1
  400. package/dist/src/document-model/gen/state/object.d.ts +0 -13
  401. package/dist/src/document-model/gen/state/object.d.ts.map +0 -1
  402. package/dist/src/document-model/gen/state/object.js +0 -23
  403. package/dist/src/document-model/gen/state/object.js.map +0 -1
  404. package/dist/src/document-model/gen/state/operations.d.ts +0 -11
  405. package/dist/src/document-model/gen/state/operations.d.ts.map +0 -1
  406. package/dist/src/document-model/gen/state/operations.js +0 -2
  407. package/dist/src/document-model/gen/state/operations.js.map +0 -1
  408. package/dist/src/document-model/gen/types.d.ts +0 -7
  409. package/dist/src/document-model/gen/types.d.ts.map +0 -1
  410. package/dist/src/document-model/gen/types.js.map +0 -1
  411. package/dist/src/document-model/gen/utils.d.ts +0 -11
  412. package/dist/src/document-model/gen/utils.d.ts.map +0 -1
  413. package/dist/src/document-model/gen/utils.js +0 -33
  414. package/dist/src/document-model/gen/utils.js.map +0 -1
  415. package/dist/src/document-model/gen/versioning/actions.d.ts +0 -9
  416. package/dist/src/document-model/gen/versioning/actions.d.ts.map +0 -1
  417. package/dist/src/document-model/gen/versioning/actions.js +0 -2
  418. package/dist/src/document-model/gen/versioning/actions.js.map +0 -1
  419. package/dist/src/document-model/gen/versioning/creators.d.ts +0 -8
  420. package/dist/src/document-model/gen/versioning/creators.d.ts.map +0 -1
  421. package/dist/src/document-model/gen/versioning/creators.js +0 -13
  422. package/dist/src/document-model/gen/versioning/creators.js.map +0 -1
  423. package/dist/src/document-model/gen/versioning/object.d.ts +0 -13
  424. package/dist/src/document-model/gen/versioning/object.d.ts.map +0 -1
  425. package/dist/src/document-model/gen/versioning/object.js +0 -20
  426. package/dist/src/document-model/gen/versioning/object.js.map +0 -1
  427. package/dist/src/document-model/gen/versioning/operations.d.ts +0 -10
  428. package/dist/src/document-model/gen/versioning/operations.d.ts.map +0 -1
  429. package/dist/src/document-model/gen/versioning/operations.js +0 -2
  430. package/dist/src/document-model/gen/versioning/operations.js.map +0 -1
  431. package/dist/test/document/object.test.d.ts +0 -2
  432. package/dist/test/document/object.test.d.ts.map +0 -1
  433. package/dist/test/document/object.test.js +0 -13
  434. package/dist/test/document/object.test.js.map +0 -1
  435. package/dist/test/document-model/object.test.d.ts +0 -2
  436. package/dist/test/document-model/object.test.d.ts.map +0 -1
  437. package/dist/test/document-model/object.test.js +0 -243
  438. package/dist/test/document-model/object.test.js.map +0 -1
  439. /package/dist/src/{document-model/gen/schema → core}/types.js +0 -0
  440. /package/dist/{src/document-model/gen → test}/types.js +0 -0
@@ -1,183 +0,0 @@
1
- import { loadState, prune, redo, setName, undo } from "./actions/creators.js";
2
- import { readOnly } from "./utils/base.js";
3
- import { baseLoadFromFile, baseSaveToFile } from "./utils/file.js";
4
- /**
5
- * This is an abstract class representing a document and provides methods
6
- * for creating and manipulating documents.
7
- * @typeparam T - The type of data stored in the document.
8
- * @typeparam A - The type of action the document can take.
9
- */
10
- export class BaseDocumentClass {
11
- _document;
12
- _reducer;
13
- _signalDispatch;
14
- /**
15
- * Constructs a BaseDocument instance with an initial state.
16
- * @param reducer - The reducer function that updates the state.
17
- * @param document - The initial state of the document.
18
- */
19
- constructor(reducer, document, signalDispatch) {
20
- this._reducer = reducer;
21
- this._document = document;
22
- this._signalDispatch = signalDispatch;
23
- }
24
- /**
25
- * Dispatches an action to update the state of the document.
26
- * @param action - The action to dispatch.
27
- * @returns The Document instance.
28
- */
29
- dispatch(action, options) {
30
- this._document = this._reducer(this._document, action, this._signalDispatch, options);
31
- return this;
32
- }
33
- /**
34
- * Saves the state of the document to a file.
35
- * @param path - The file path where the state should be saved.
36
- * @param extension - The file extension to use when saving the state.
37
- * @returns The file path where the state was saved.
38
- */
39
- saveToFile(path, extension, name) {
40
- return baseSaveToFile(this._document, path, extension, name);
41
- }
42
- /**
43
- * Loads the state of the document from a file.
44
- * @param path - The file path where the state is stored.
45
- */
46
- async loadFromFile(path) {
47
- this._document = await baseLoadFromFile(path, this._reducer);
48
- }
49
- /**
50
- * Loads the state of the document from a file and returns it.
51
- * @param path - The file path where the state is stored.
52
- * @param reducer - The reducer function that updates the state.
53
- * @returns The state of the document.
54
- */
55
- static async stateFromFile(path, reducer) {
56
- const state = await baseLoadFromFile(path, reducer);
57
- return state;
58
- }
59
- /**
60
- * Gets the current state of the document.
61
- */
62
- get state() {
63
- return readOnly(this._document.state);
64
- }
65
- /**
66
- * Gets the list of operations performed on the document.
67
- */
68
- get operations() {
69
- return readOnly(this._document.operations);
70
- }
71
- /**
72
- * Gets the name of the document.
73
- */
74
- get name() {
75
- return this._document.header.name;
76
- }
77
- /**
78
- * Gets the type of document.
79
- */
80
- get documentType() {
81
- return this._document.header.documentType;
82
- }
83
- /**
84
- * Gets the timestamp of the date the document was created.
85
- */
86
- get created() {
87
- return this._document.header.createdAtUtcIso;
88
- }
89
- /**
90
- * Gets the timestamp of the date the document was last modified.
91
- */
92
- get lastModified() {
93
- return this._document.header.lastModifiedAtUtcIso;
94
- }
95
- getRevision(scope) {
96
- return this._document.header.revision[scope] || 0;
97
- }
98
- /**
99
- * Gets the initial state of the document.
100
- */
101
- get initialState() {
102
- return readOnly(this._document.initialState);
103
- }
104
- /**
105
- * Returns the current document as an object
106
- */
107
- toDocument() {
108
- return readOnly(this._document);
109
- }
110
- /**
111
- * Gets the attachment associated with the given key.
112
- * @param attachment - The key of the attachment to retrieve.
113
- */
114
- getAttachment(attachment) {
115
- return this._document.attachments?.[attachment];
116
- }
117
- /**
118
- * Sets the name of the document.
119
- * @param name - The new name of the document.
120
- */
121
- setName(name) {
122
- this.dispatch(setName(name));
123
- return this;
124
- }
125
- /**
126
- * Reverts a number of actions from the document.
127
- * @param count - The number of actions to revert.
128
- */
129
- undo(count) {
130
- this.dispatch(undo(count));
131
- return this;
132
- }
133
- /**
134
- * Reapplies a number of actions to the document.
135
- * @param count - The number of actions to reapply.
136
- */
137
- redo(count) {
138
- this.dispatch(redo(count));
139
- return this;
140
- }
141
- /**
142
- * Removes a range of operations from the document.
143
- * @param start - The starting index of the range to remove.
144
- * @param end - The ending index of the range to remove.
145
- */
146
- prune(start, end) {
147
- this.dispatch(prune(start, end));
148
- return this;
149
- }
150
- /**
151
- * Loads a document state and a set of operations.
152
- * @param state - The state to load.
153
- * @param operations - The operations to apply to the document.
154
- */
155
- loadState(state, operations) {
156
- this.dispatch(loadState(state, operations));
157
- return this;
158
- }
159
- }
160
- /**
161
- * Applies multiple mixins to a base class.
162
- * Used to have separate mixins to group methods by actions.
163
- *
164
- * @remarks
165
- * {@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern}
166
- *
167
- * @param derivedCtor - The class to apply the mixins to.
168
- * @param constructors - The constructors of the mixins.
169
- */
170
- export function applyMixins(derivedCtor, constructors) {
171
- constructors.forEach((baseCtor) => {
172
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
173
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
174
- Object.defineProperty(
175
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
176
- derivedCtor.prototype, name,
177
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
178
- Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
179
- Object.create(null));
180
- });
181
- });
182
- }
183
- //# sourceMappingURL=object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/document/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAa9E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,OAAgB,iBAAiB;IAK3B,SAAS,CAAyD;IACpE,QAAQ,CAEd;IACM,eAAe,CAAkB;IAEzC;;;;OAIG;IACH,YACE,OAAwE,EACxE,QAAgE,EAChE,cAA+B;QAE/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACO,QAAQ,CAChB,MAAiD,EACjD,OAAwB;QAExB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAC5B,IAAI,CAAC,SAAS,EACd,MAAM,EACN,IAAI,CAAC,eAAe,EACpB,OAAO,CACR,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACO,UAAU,CAAC,IAAY,EAAE,SAAiB,EAAE,IAAa;QACjE,OAAO,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,CAAC,IAAY;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;OAKG;IACO,MAAM,CA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ACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,68 +0,0 @@
1
- export type JsonSerializable = string | number | boolean | null | undefined | JsonSerializable[] | {
2
- [key: string]: JsonSerializable;
3
- };
4
- export type PHDocumentSignatureInfo = {
5
- /**
6
- * The public key of the document creator.
7
- **/
8
- publicKey: JsonWebKey;
9
- /** The nonce that was appended to the message to create the signature. */
10
- nonce: string;
11
- };
12
- /** Meta information about the document. */
13
- export type PHDocumentMeta = {
14
- /** The preferred editor for the document. */
15
- preferredEditor?: string;
16
- };
17
- export type PHDocumentHeader = {
18
- /**
19
- * The id of the document.
20
- *
21
- * This is a Ed25519 signature and is immutable.
22
- **/
23
- id: string;
24
- /**
25
- * Information to verify the document creator.
26
- *
27
- * This is immutable.
28
- **/
29
- sig: PHDocumentSignatureInfo;
30
- /**
31
- * The type of the document.
32
- *
33
- * This is used as part of the signature payload and thus, cannot be changed
34
- * after the document header has been created.
35
- **/
36
- documentType: string;
37
- /**
38
- * The timestamp of the creation date of the document, in UTC ISO format.
39
- *
40
- * This is used as part of the signature payload and thus, cannot be changed
41
- * after the document header has been created.
42
- **/
43
- createdAtUtcIso: string;
44
- /** The slug of the document. */
45
- slug: string;
46
- /** The name of the document. */
47
- name: string;
48
- /** The branch of this document. */
49
- branch: string;
50
- /**
51
- * The revision of each scope of the document. This object is updated every
52
- * time any _other_ scope is updated.
53
- */
54
- revision: {
55
- [scope: string]: number;
56
- };
57
- /**
58
- * The timestamp of the last change in the document, in UTC ISO format.
59
- **/
60
- lastModifiedAtUtcIso: string;
61
- /** Meta information about the document. */
62
- meta?: PHDocumentMeta;
63
- };
64
- export type PHBaseState<TDocumentState = JsonSerializable> = {
65
- document?: TDocumentState;
66
- };
67
- export type PHDocumentHistory = {};
68
- //# sourceMappingURL=ph-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ph-types.d.ts","sourceRoot":"","sources":["../../../src/document/ph-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAg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"],"names":[],"mappings":""}
@@ -1,49 +0,0 @@
1
- import { type SignalDispatch } from "./signal.js";
2
- import { type Action, type ActionFromDocument, type DefaultAction, type Operation, type OperationFromDocument, type PHDocument, type ReducerOptions, type StateReducer } from "./types.js";
3
- /**
4
- * Updates the document header with the latest revision number and
5
- * date of last modification.
6
- *
7
- * @param state The current state of the document.
8
- * @param operation The action being applied to the document.
9
- * @returns The updated document state.
10
- */
11
- export declare function updateHeader<TDocument extends PHDocument>(document: TDocument, action: Action | DefaultAction | Operation): TDocument;
12
- /**
13
- * Updates the document state based on the provided action.
14
- *
15
- * @param state The current state of the document.
16
- * @param action The action being applied to the document.
17
- * @param skip The number of operations to skip before applying the action.
18
- * @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
19
- * @returns The updated document state.
20
- */
21
- export declare function updateDocument<TDocument extends PHDocument>(document: TDocument, action: Action | Operation, skip?: number, reuseLastOperationIndex?: boolean): TDocument;
22
- /**
23
- * Processes an UNDO or REDO action.
24
- *
25
- * @param document The current state of the document.
26
- * @param action The action being applied to the document.
27
- * @param skip The number of operations to skip before applying the action.
28
- * @returns The updated document, calculated skip value and transformed action (if applied).
29
- */
30
- export declare function processUndoRedo<TDocument extends PHDocument>(document: TDocument, action: ActionFromDocument<TDocument> | OperationFromDocument<TDocument> | DefaultAction, skip: number): {
31
- document: TDocument;
32
- action: ActionFromDocument<TDocument> | OperationFromDocument<TDocument>;
33
- skip: number;
34
- reuseLastOperationIndex: boolean;
35
- };
36
- /**
37
- * Base document reducer that wraps a custom document reducer and handles
38
- * document-level actions such as undo, redo, prune, and set name.
39
- *
40
- * @template TGlobalState - The type of the state of the custom reducer.
41
- * @template TAction - The type of the actions of the custom reducer.
42
- * @param state - The current state of the document.
43
- * @param action - The action object to apply to the state.
44
- * @param customReducer - The custom reducer that implements the application logic
45
- * specific to the document's state.
46
- * @returns The new state of the document.
47
- */
48
- export declare function baseReducer<TDocument extends PHDocument>(document: TDocument, action: Action | Operation, customReducer: StateReducer<TDocument>, dispatch?: SignalDispatch, options?: ReducerOptions): TDocument;
49
- //# sourceMappingURL=reducer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/document/reducer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,KAAK,MAAM,EACX,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AA0CpB;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,SAAS,UAAU,EACvD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,GACzC,SAAS,CAcX;AA4ED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,SAAS,SAAS,UAAU,EACzD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,SAAI,EACR,uBAAuB,UAAQ,GAC9B,SAAS,CASX;AAiCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,SAAS,UAAU,EAC1D,QAAQ,EAAE,SAAS,EACnB,MAAM,EACF,kBAAkB,CAAC,SAAS,CAAC,GAC7B,qBAAqB,CAAC,SAAS,CAAC,GAChC,aAAa,EACjB,IAAI,EAAE,MAAM,GACX;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,kBAAkB,CAAC,SAAS,CAAC,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB,EAAE,OAAO,CAAC;CAClC,CASA;AAuGD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,SAAS,SAAS,UAAU,EACtD,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,YAAY,CAAC,SAAS,CAAC,EACtC,QAAQ,CAAC,EAAE,cAAc,EACzB,OAAO,GAAE,cAAmB,GAC3B,SAAS,CA2KX"}
@@ -1,346 +0,0 @@
1
- import { castDraft, create, unsafe } from "mutative";
2
- import { loadStateOperation, pruneOperation, redoOperation, setNameOperation, undoOperation, } from "./actions/operations.js";
3
- import { LOAD_STATE, PRUNE, REDO, SET_NAME, UNDO } from "./actions/types.js";
4
- import { DocumentActionSchema } from "./schema/zod.js";
5
- import { getDocumentLastModified, hashDocumentStateForScope, isDocumentAction, isUndo, isUndoRedo, parseResultingState, replayOperations, } from "./utils/base.js";
6
- import { generateId } from "./utils/crypto.js";
7
- import { diffOperations, garbageCollect, garbageCollectDocumentOperations, skipHeaderOperations, sortOperations, } from "./utils/document-helpers.js";
8
- /**
9
- * Gets the next revision number based on the provided action.
10
- *
11
- * @param state The current state of the document.
12
- * @param operation The action being applied to the document.
13
- * @returns The next revision number.
14
- */
15
- function getNextRevision(document, operation) {
16
- let latestOperationIndex;
17
- if ("index" in operation) {
18
- latestOperationIndex = operation.index;
19
- }
20
- else {
21
- latestOperationIndex =
22
- document.operations[operation.scope].at(-1)?.index ?? -1;
23
- }
24
- return (latestOperationIndex ?? -1) + 1;
25
- }
26
- /**
27
- * Updates the document header with the latest revision number and
28
- * date of last modification.
29
- *
30
- * @param state The current state of the document.
31
- * @param operation The action being applied to the document.
32
- * @returns The updated document state.
33
- */
34
- export function updateHeader(document, action) {
35
- const header = {
36
- ...document.header,
37
- revision: {
38
- ...document.header.revision,
39
- [action.scope]: getNextRevision(document, action),
40
- },
41
- lastModifiedAtUtcIso: getDocumentLastModified(document),
42
- };
43
- return {
44
- ...document,
45
- header,
46
- };
47
- }
48
- /**
49
- * Updates the operations history of the document based on the provided action.
50
- *
51
- * @param state The current state of the document.
52
- * @param actionOrOperation The action being applied to the document.
53
- * @param skip The number of operations to skip before applying the action.
54
- * @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
55
- * @returns The updated document state.
56
- */
57
- function updateOperations(document, actionOrOperation, skip = 0, reuseLastOperationIndex = false) {
58
- // UNDO, REDO and PRUNE are meta operations
59
- // that alter the operations history themselves
60
- if ("type" in actionOrOperation &&
61
- [UNDO, REDO, PRUNE].includes(actionOrOperation.type)) {
62
- return document;
63
- }
64
- const { scope } = actionOrOperation;
65
- const operations = document.operations[scope].slice();
66
- let operationId;
67
- const latestOperation = operations.sort((a, b) => a.index - b.index).at(-1);
68
- const lastOperationIndex = latestOperation?.index ?? -1;
69
- let nextIndex = reuseLastOperationIndex
70
- ? lastOperationIndex
71
- : lastOperationIndex + 1;
72
- let timestamp = new Date().toISOString();
73
- if ("index" in actionOrOperation) {
74
- if (actionOrOperation.index - skip > nextIndex) {
75
- throw new Error(`Missing operations: expected ${nextIndex} with skip 0 or equivalent, got index ${actionOrOperation.index} with skip ${skip}`);
76
- }
77
- nextIndex = actionOrOperation.index;
78
- operationId = actionOrOperation.id;
79
- timestamp = actionOrOperation.timestamp;
80
- }
81
- else {
82
- operationId =
83
- "id" in actionOrOperation
84
- ? actionOrOperation.id
85
- : generateId();
86
- }
87
- operations.push({
88
- ...actionOrOperation,
89
- id: operationId,
90
- index: nextIndex,
91
- timestamp,
92
- hash: "",
93
- scope,
94
- skip,
95
- error: undefined,
96
- });
97
- // adds the action to the operations history with
98
- // the latest index and current timestamp
99
- return {
100
- ...document,
101
- operations: { ...document.operations, [scope]: operations },
102
- };
103
- }
104
- /**
105
- * Updates the document state based on the provided action.
106
- *
107
- * @param state The current state of the document.
108
- * @param action The action being applied to the document.
109
- * @param skip The number of operations to skip before applying the action.
110
- * @param reuseLastOperationIndex Whether to reuse the last operation index (used when a an UNDO operation is performed after an existing one).
111
- * @returns The updated document state.
112
- */
113
- export function updateDocument(document, action, skip = 0, reuseLastOperationIndex = false) {
114
- let newDocument = updateOperations(document, action, skip, reuseLastOperationIndex);
115
- newDocument = updateHeader(newDocument, action);
116
- return newDocument;
117
- }
118
- /**
119
- * The base document reducer function that wraps a custom reducer function.
120
- *
121
- * @param state The current state of the document.
122
- * @param action The action being applied to the document.
123
- * @param wrappedReducer The custom reducer function being wrapped by the base reducer.
124
- * @returns The updated document state.
125
- */
126
- function _baseReducer(document, action, wrappedReducer) {
127
- // throws if action is not valid base action
128
- const parsedAction = DocumentActionSchema().parse(action);
129
- switch (parsedAction.type) {
130
- case SET_NAME:
131
- return setNameOperation(document, parsedAction.input);
132
- case PRUNE:
133
- return pruneOperation(document, parsedAction.input, wrappedReducer);
134
- case LOAD_STATE:
135
- return loadStateOperation(document, parsedAction.input.state);
136
- default:
137
- return document;
138
- }
139
- }
140
- /**
141
- * Processes an UNDO or REDO action.
142
- *
143
- * @param document The current state of the document.
144
- * @param action The action being applied to the document.
145
- * @param skip The number of operations to skip before applying the action.
146
- * @returns The updated document, calculated skip value and transformed action (if applied).
147
- */
148
- export function processUndoRedo(document, action, skip) {
149
- switch (action.type) {
150
- case UNDO:
151
- return undoOperation(document, action, skip);
152
- case REDO:
153
- return redoOperation(document, action, skip);
154
- default:
155
- return { document, action, skip, reuseLastOperationIndex: false };
156
- }
157
- }
158
- function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
159
- const scope = action.scope;
160
- const latestOperation = document.operations[scope].at(-1);
161
- if (!latestOperation)
162
- return document;
163
- const documentOperations = garbageCollectDocumentOperations({
164
- ...document.operations,
165
- [scope]: skipHeaderOperations(document.operations[scope], latestOperation),
166
- });
167
- let scopeState = undefined;
168
- const lastRemainingOperation = documentOperations[scope].at(-1);
169
- // if the last operation has the resulting state and
170
- // reuseOperationResultingState is true then reuses it
171
- // instead of replaying the operations from the beginning
172
- if (reuseOperationResultingState && lastRemainingOperation?.resultingState) {
173
- scopeState = resultingStateParser(lastRemainingOperation.resultingState);
174
- }
175
- else {
176
- const { state } = replayOperations(document.initialState, documentOperations, customReducer, undefined, undefined, undefined, undefined, {
177
- reuseHash: true,
178
- reuseOperationResultingState,
179
- operationResultingStateParser: resultingStateParser,
180
- });
181
- scopeState = state[scope];
182
- }
183
- return {
184
- ...document,
185
- state: {
186
- ...document.state,
187
- [scope]: scopeState,
188
- },
189
- operations: garbageCollectDocumentOperations({
190
- ...document.operations,
191
- }),
192
- };
193
- }
194
- function processUndoOperation(document, scope, customReducer, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
195
- const operations = [...document.operations[scope]];
196
- const sortedOperations = sortOperations(operations);
197
- sortedOperations.pop();
198
- const documentOperations = garbageCollectDocumentOperations({
199
- ...document.operations,
200
- });
201
- const clearedOperations = [...documentOperations[scope]];
202
- const diff = diffOperations(garbageCollect(sortedOperations), clearedOperations);
203
- const doc = replayOperations(document.initialState, documentOperations, customReducer, undefined, undefined, undefined, undefined, {
204
- reuseHash: true,
205
- reuseOperationResultingState,
206
- operationResultingStateParser: resultingStateParser,
207
- });
208
- const clipboard = sortOperations([...document.clipboard, ...diff].filter((op) => op.type !== "NOOP")).reverse();
209
- return { ...doc, clipboard };
210
- }
211
- /**
212
- * Base document reducer that wraps a custom document reducer and handles
213
- * document-level actions such as undo, redo, prune, and set name.
214
- *
215
- * @template TGlobalState - The type of the state of the custom reducer.
216
- * @template TAction - The type of the actions of the custom reducer.
217
- * @param state - The current state of the document.
218
- * @param action - The action object to apply to the state.
219
- * @param customReducer - The custom reducer that implements the application logic
220
- * specific to the document's state.
221
- * @returns The new state of the document.
222
- */
223
- export function baseReducer(document, action, customReducer, dispatch, options = {}) {
224
- const { skip, ignoreSkipOperations = false, reuseHash = false, reuseOperationResultingState = false, operationResultingStateParser, } = options;
225
- let _action = { ...action };
226
- let skipValue = skip || 0;
227
- let newDocument = {
228
- ...document,
229
- };
230
- let reuseLastOperationIndex = false;
231
- const shouldProcessSkipOperation = !ignoreSkipOperations &&
232
- (skipValue > 0 ||
233
- ("index" in _action &&
234
- "skip" in _action &&
235
- typeof _action.skip === "number" &&
236
- _action.skip > 0));
237
- if (isUndoRedo(_action)) {
238
- const { skip: calculatedSkip, action: transformedAction, document: processedDocument, reuseLastOperationIndex: reuseIndex, } = processUndoRedo(document, _action, skipValue);
239
- _action = transformedAction;
240
- skipValue = calculatedSkip;
241
- newDocument = processedDocument;
242
- reuseLastOperationIndex = reuseIndex;
243
- }
244
- else {
245
- newDocument = {
246
- ...newDocument,
247
- clipboard: [],
248
- };
249
- }
250
- // if the action is one the base document actions (SET_NAME, UNDO, REDO, PRUNE)
251
- // then runs the base reducer first
252
- if (isDocumentAction(_action)) {
253
- newDocument = _baseReducer(newDocument, _action, customReducer);
254
- }
255
- // updates the document revision number, last modified date
256
- // and operation history
257
- newDocument = updateDocument(newDocument, _action, skipValue, reuseLastOperationIndex);
258
- const isUndoAction = isUndo(action);
259
- if (isUndoAction) {
260
- const result = processUndoOperation(newDocument, action.scope, customReducer);
261
- return result;
262
- }
263
- if (shouldProcessSkipOperation) {
264
- newDocument = processSkipOperation(newDocument, _action, customReducer, skipValue, reuseOperationResultingState, operationResultingStateParser);
265
- }
266
- // wraps the custom reducer with Mutative to avoid
267
- // mutation bugs and allow writing reducers with
268
- // mutating code
269
- newDocument = create(newDocument, (draft) => {
270
- // the reducer runs on a immutable version of
271
- // provided state
272
- try {
273
- const newState = customReducer(draft.state, _action, dispatch);
274
- // const clipboardValue = isUndoRedo(action) ? [...clipboard] : [];
275
- // if the reducer creates a new state object instead
276
- // of mutating the draft then returns the new state
277
- if (newState) {
278
- // Object.assign(draft.state, newState);
279
- unsafe(() => {
280
- // casts new state as draft to comply with typescript
281
- draft.state = castDraft(newState);
282
- // clipboard: [...clipboardValue],
283
- });
284
- }
285
- else {
286
- // unsafe(() => {
287
- // draft.clipboard = castDraft([...clipboardValue]);
288
- // });
289
- }
290
- }
291
- catch (error) {
292
- // if the reducer throws an error then we should keep the previous state (before replayOperations)
293
- // and remove skip number from action/operation
294
- const lastOperationIndex = newDocument.operations[_action.scope].length - 1;
295
- draft.operations[_action.scope][lastOperationIndex].error = error.message;
296
- draft.operations[_action.scope][lastOperationIndex].skip = 0;
297
- if (shouldProcessSkipOperation) {
298
- draft.state = castDraft({
299
- ...document.state,
300
- });
301
- draft.operations = castDraft({
302
- ...document.operations,
303
- [_action.scope]: [
304
- ...document.operations[_action.scope],
305
- {
306
- ...draft.operations[_action.scope][lastOperationIndex],
307
- },
308
- ],
309
- });
310
- }
311
- }
312
- });
313
- // updates the document history
314
- // meta operations are not added to the operations history
315
- if ([UNDO, REDO, PRUNE].includes(_action.type)) {
316
- return newDocument;
317
- }
318
- // if reuseHash is true, checks if the action has
319
- // an hash and uses it instead of generating it
320
- const scope = _action.scope || "global";
321
- const hash = reuseHash && Object.prototype.hasOwnProperty.call(_action, "hash")
322
- ? _action.hash
323
- : hashDocumentStateForScope(newDocument, scope);
324
- // updates the last operation with the hash of the resulting state
325
- const lastOperation = newDocument.operations[scope].at(-1);
326
- if (lastOperation) {
327
- lastOperation.hash = hash;
328
- if (reuseOperationResultingState) {
329
- lastOperation.resultingState = JSON.stringify(newDocument.state[scope]);
330
- }
331
- // if the action has attachments then adds them to the document
332
- if (!isDocumentAction(_action) && _action.attachments) {
333
- _action.attachments.forEach((attachment) => {
334
- const { hash, ...file } = attachment;
335
- if (!newDocument.attachments) {
336
- newDocument.attachments = {};
337
- }
338
- newDocument.attachments[hash] = {
339
- ...file,
340
- };
341
- });
342
- }
343
- }
344
- return newDocument;
345
- }
346
- //# sourceMappingURL=reducer.js.map