@verdant-web/store 2.0.1 → 2.0.2

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 (560) hide show
  1. package/dist/cjs/BackoffScheduler.d.ts +19 -19
  2. package/dist/cjs/BackoffScheduler.js +44 -44
  3. package/dist/cjs/DocumentManager.d.ts +28 -28
  4. package/dist/cjs/DocumentManager.js +44 -44
  5. package/dist/cjs/IDBService.d.ts +9 -9
  6. package/dist/cjs/IDBService.js +46 -46
  7. package/dist/cjs/UndoHistory.d.ts +16 -16
  8. package/dist/cjs/UndoHistory.js +50 -50
  9. package/dist/cjs/__tests__/batching.test.d.ts +1 -1
  10. package/dist/cjs/__tests__/batching.test.js +44 -44
  11. package/dist/cjs/__tests__/documents.test.d.ts +1 -1
  12. package/dist/cjs/__tests__/documents.test.js +398 -398
  13. package/dist/cjs/__tests__/fixtures/testStorage.d.ts +118 -118
  14. package/dist/cjs/__tests__/fixtures/testStorage.js +115 -115
  15. package/dist/cjs/__tests__/queries.test.d.ts +1 -1
  16. package/dist/cjs/__tests__/queries.test.js +262 -262
  17. package/dist/cjs/__tests__/setup/indexedDB.d.ts +1 -1
  18. package/dist/cjs/__tests__/setup/indexedDB.js +3 -3
  19. package/dist/cjs/__tests__/undo.test.d.ts +1 -1
  20. package/dist/cjs/__tests__/undo.test.js +86 -86
  21. package/dist/cjs/client/Client.d.ts +86 -86
  22. package/dist/cjs/client/Client.js +226 -226
  23. package/dist/cjs/client/ClientDescriptor.d.ts +62 -62
  24. package/dist/cjs/client/ClientDescriptor.js +108 -108
  25. package/dist/cjs/constants.d.ts +1 -1
  26. package/dist/cjs/constants.js +4 -4
  27. package/dist/cjs/context.d.ts +17 -17
  28. package/dist/cjs/context.js +2 -2
  29. package/dist/cjs/files/EntityFile.d.ts +27 -27
  30. package/dist/cjs/files/EntityFile.js +71 -71
  31. package/dist/cjs/files/FileManager.d.ts +42 -42
  32. package/dist/cjs/files/FileManager.js +145 -145
  33. package/dist/cjs/files/FileStorage.d.ts +27 -27
  34. package/dist/cjs/files/FileStorage.js +93 -93
  35. package/dist/cjs/files/utils.d.ts +8 -8
  36. package/dist/cjs/files/utils.js +55 -55
  37. package/dist/cjs/files/utils.test.d.ts +1 -1
  38. package/dist/cjs/files/utils.test.js +80 -80
  39. package/dist/cjs/idb.d.ts +8 -8
  40. package/dist/cjs/idb.js +87 -87
  41. package/dist/cjs/index.d.ts +19 -19
  42. package/dist/cjs/index.js +20 -20
  43. package/dist/cjs/indexes.d.ts +3 -3
  44. package/dist/cjs/indexes.js +19 -19
  45. package/dist/cjs/metadata/AckInfoStore.d.ts +10 -10
  46. package/dist/cjs/metadata/AckInfoStore.js +25 -25
  47. package/dist/cjs/metadata/BaselinesStore.d.ts +33 -33
  48. package/dist/cjs/metadata/BaselinesStore.js +59 -59
  49. package/dist/cjs/metadata/LocalReplicaStore.d.ts +17 -17
  50. package/dist/cjs/metadata/LocalReplicaStore.js +47 -47
  51. package/dist/cjs/metadata/MessageCreator.d.ts +19 -19
  52. package/dist/cjs/metadata/MessageCreator.js +127 -127
  53. package/dist/cjs/metadata/Metadata.d.ts +106 -106
  54. package/dist/cjs/metadata/Metadata.js +336 -336
  55. package/dist/cjs/metadata/OperationsStore.d.ts +50 -50
  56. package/dist/cjs/metadata/OperationsStore.js +145 -145
  57. package/dist/cjs/metadata/SchemaStore.d.ts +9 -9
  58. package/dist/cjs/metadata/SchemaStore.js +38 -38
  59. package/dist/cjs/metadata/openMetadataDatabase.d.ts +8 -8
  60. package/dist/cjs/metadata/openMetadataDatabase.js +105 -105
  61. package/dist/cjs/openDocumentDatabase.d.ts +12 -12
  62. package/dist/cjs/openDocumentDatabase.js +424 -424
  63. package/dist/cjs/queries2/BaseQuery.d.ts +39 -39
  64. package/dist/cjs/queries2/BaseQuery.js +98 -98
  65. package/dist/cjs/queries2/CollectionQueries.d.ts +55 -55
  66. package/dist/cjs/queries2/CollectionQueries.js +82 -82
  67. package/dist/cjs/queries2/FindAllQuery.d.ts +11 -11
  68. package/dist/cjs/queries2/FindAllQuery.js +33 -33
  69. package/dist/cjs/queries2/FindInfiniteQuery.d.ts +18 -18
  70. package/dist/cjs/queries2/FindInfiniteQuery.js +60 -60
  71. package/dist/cjs/queries2/FindOneQuery.d.ts +11 -11
  72. package/dist/cjs/queries2/FindOneQuery.js +33 -33
  73. package/dist/cjs/queries2/FindPageQuery.d.ts +23 -23
  74. package/dist/cjs/queries2/FindPageQuery.js +67 -67
  75. package/dist/cjs/queries2/GetQuery.d.ts +10 -10
  76. package/dist/cjs/queries2/GetQuery.js +29 -29
  77. package/dist/cjs/queries2/QueryCache.d.ts +16 -16
  78. package/dist/cjs/queries2/QueryCache.js +39 -39
  79. package/dist/cjs/queries2/dbQueries.d.ts +22 -22
  80. package/dist/cjs/queries2/dbQueries.js +125 -125
  81. package/dist/cjs/queries2/keys.d.ts +10 -10
  82. package/dist/cjs/queries2/keys.js +33 -33
  83. package/dist/cjs/queries2/ranges.d.ts +2 -2
  84. package/dist/cjs/queries2/ranges.js +69 -69
  85. package/dist/cjs/queries2/types.d.ts +6 -6
  86. package/dist/cjs/queries2/types.js +2 -2
  87. package/dist/cjs/queries2/utils.d.ts +1 -1
  88. package/dist/cjs/queries2/utils.js +19 -19
  89. package/dist/cjs/reactives/DocumentFamiliyCache.d.ts +47 -47
  90. package/dist/cjs/reactives/DocumentFamiliyCache.js +210 -210
  91. package/dist/cjs/reactives/Entity.d.ts +191 -191
  92. package/dist/cjs/reactives/Entity.js +462 -462
  93. package/dist/cjs/reactives/EntityStore.d.ts +84 -84
  94. package/dist/cjs/reactives/EntityStore.js +421 -421
  95. package/dist/cjs/reactives/FakeWeakRef.d.ts +11 -11
  96. package/dist/cjs/reactives/FakeWeakRef.js +18 -18
  97. package/dist/cjs/sync/FileSync.d.ts +23 -23
  98. package/dist/cjs/sync/FileSync.js +84 -84
  99. package/dist/cjs/sync/Heartbeat.d.ts +24 -24
  100. package/dist/cjs/sync/Heartbeat.js +55 -55
  101. package/dist/cjs/sync/PresenceManager.d.ts +41 -41
  102. package/dist/cjs/sync/PresenceManager.js +107 -107
  103. package/dist/cjs/sync/PushPullSync.d.ts +36 -36
  104. package/dist/cjs/sync/PushPullSync.js +141 -141
  105. package/dist/cjs/sync/ServerSyncEndpointProvider.d.ts +27 -27
  106. package/dist/cjs/sync/ServerSyncEndpointProvider.js +64 -64
  107. package/dist/cjs/sync/Sync.d.ts +127 -127
  108. package/dist/cjs/sync/Sync.js +244 -244
  109. package/dist/cjs/sync/WebSocketSync.d.ts +41 -41
  110. package/dist/cjs/sync/WebSocketSync.js +183 -183
  111. package/dist/cjs/types.d.ts +5 -5
  112. package/dist/cjs/types.js +2 -2
  113. package/dist/cjs/utils/Disposable.d.ts +6 -6
  114. package/dist/cjs/utils/Disposable.js +18 -18
  115. package/dist/cjs/utils/Resolvable.d.ts +8 -8
  116. package/dist/cjs/utils/Resolvable.js +22 -22
  117. package/dist/esm/BackoffScheduler.d.ts +19 -19
  118. package/dist/esm/BackoffScheduler.js +39 -39
  119. package/dist/esm/DocumentManager.d.ts +28 -28
  120. package/dist/esm/DocumentManager.js +40 -40
  121. package/dist/esm/IDBService.d.ts +9 -9
  122. package/dist/esm/IDBService.js +42 -42
  123. package/dist/esm/UndoHistory.d.ts +16 -16
  124. package/dist/esm/UndoHistory.js +46 -46
  125. package/dist/esm/__tests__/batching.test.d.ts +1 -1
  126. package/dist/esm/__tests__/batching.test.js +42 -42
  127. package/dist/esm/__tests__/documents.test.d.ts +1 -1
  128. package/dist/esm/__tests__/documents.test.js +396 -396
  129. package/dist/esm/__tests__/fixtures/testStorage.d.ts +118 -118
  130. package/dist/esm/__tests__/fixtures/testStorage.js +111 -111
  131. package/dist/esm/__tests__/queries.test.d.ts +1 -1
  132. package/dist/esm/__tests__/queries.test.js +260 -260
  133. package/dist/esm/__tests__/setup/indexedDB.d.ts +1 -1
  134. package/dist/esm/__tests__/setup/indexedDB.js +1 -1
  135. package/dist/esm/__tests__/undo.test.d.ts +1 -1
  136. package/dist/esm/__tests__/undo.test.js +84 -84
  137. package/dist/esm/client/Client.d.ts +86 -86
  138. package/dist/esm/client/Client.js +222 -222
  139. package/dist/esm/client/ClientDescriptor.d.ts +62 -62
  140. package/dist/esm/client/ClientDescriptor.js +104 -104
  141. package/dist/esm/constants.d.ts +1 -1
  142. package/dist/esm/constants.js +1 -1
  143. package/dist/esm/context.d.ts +17 -17
  144. package/dist/esm/context.js +1 -1
  145. package/dist/esm/files/EntityFile.d.ts +27 -27
  146. package/dist/esm/files/EntityFile.js +67 -67
  147. package/dist/esm/files/FileManager.d.ts +42 -42
  148. package/dist/esm/files/FileManager.js +141 -141
  149. package/dist/esm/files/FileStorage.d.ts +27 -27
  150. package/dist/esm/files/FileStorage.js +88 -88
  151. package/dist/esm/files/utils.d.ts +8 -8
  152. package/dist/esm/files/utils.js +46 -46
  153. package/dist/esm/files/utils.test.d.ts +1 -1
  154. package/dist/esm/files/utils.test.js +78 -78
  155. package/dist/esm/idb.d.ts +8 -8
  156. package/dist/esm/idb.js +79 -79
  157. package/dist/esm/index.d.ts +19 -19
  158. package/dist/esm/index.js +11 -11
  159. package/dist/esm/indexes.d.ts +3 -3
  160. package/dist/esm/indexes.js +14 -14
  161. package/dist/esm/metadata/AckInfoStore.d.ts +10 -10
  162. package/dist/esm/metadata/AckInfoStore.js +21 -21
  163. package/dist/esm/metadata/BaselinesStore.d.ts +33 -33
  164. package/dist/esm/metadata/BaselinesStore.js +55 -55
  165. package/dist/esm/metadata/LocalReplicaStore.d.ts +17 -17
  166. package/dist/esm/metadata/LocalReplicaStore.js +40 -40
  167. package/dist/esm/metadata/MessageCreator.d.ts +19 -19
  168. package/dist/esm/metadata/MessageCreator.js +123 -123
  169. package/dist/esm/metadata/Metadata.d.ts +106 -106
  170. package/dist/esm/metadata/Metadata.js +332 -332
  171. package/dist/esm/metadata/OperationsStore.d.ts +50 -50
  172. package/dist/esm/metadata/OperationsStore.js +141 -141
  173. package/dist/esm/metadata/SchemaStore.d.ts +9 -9
  174. package/dist/esm/metadata/SchemaStore.js +34 -34
  175. package/dist/esm/metadata/openMetadataDatabase.d.ts +8 -8
  176. package/dist/esm/metadata/openMetadataDatabase.js +101 -101
  177. package/dist/esm/openDocumentDatabase.d.ts +12 -12
  178. package/dist/esm/openDocumentDatabase.js +420 -420
  179. package/dist/esm/queries2/BaseQuery.d.ts +39 -39
  180. package/dist/esm/queries2/BaseQuery.js +94 -94
  181. package/dist/esm/queries2/CollectionQueries.d.ts +55 -55
  182. package/dist/esm/queries2/CollectionQueries.js +78 -78
  183. package/dist/esm/queries2/FindAllQuery.d.ts +11 -11
  184. package/dist/esm/queries2/FindAllQuery.js +29 -29
  185. package/dist/esm/queries2/FindInfiniteQuery.d.ts +18 -18
  186. package/dist/esm/queries2/FindInfiniteQuery.js +56 -56
  187. package/dist/esm/queries2/FindOneQuery.d.ts +11 -11
  188. package/dist/esm/queries2/FindOneQuery.js +29 -29
  189. package/dist/esm/queries2/FindPageQuery.d.ts +23 -23
  190. package/dist/esm/queries2/FindPageQuery.js +63 -63
  191. package/dist/esm/queries2/GetQuery.d.ts +10 -10
  192. package/dist/esm/queries2/GetQuery.js +25 -25
  193. package/dist/esm/queries2/QueryCache.d.ts +16 -16
  194. package/dist/esm/queries2/QueryCache.js +35 -35
  195. package/dist/esm/queries2/dbQueries.d.ts +22 -22
  196. package/dist/esm/queries2/dbQueries.js +119 -119
  197. package/dist/esm/queries2/keys.d.ts +10 -10
  198. package/dist/esm/queries2/keys.js +29 -29
  199. package/dist/esm/queries2/ranges.d.ts +2 -2
  200. package/dist/esm/queries2/ranges.js +65 -65
  201. package/dist/esm/queries2/types.d.ts +6 -6
  202. package/dist/esm/queries2/types.js +1 -1
  203. package/dist/esm/queries2/utils.d.ts +1 -1
  204. package/dist/esm/queries2/utils.js +15 -15
  205. package/dist/esm/reactives/DocumentFamiliyCache.d.ts +47 -47
  206. package/dist/esm/reactives/DocumentFamiliyCache.js +206 -206
  207. package/dist/esm/reactives/Entity.d.ts +191 -191
  208. package/dist/esm/reactives/Entity.js +457 -457
  209. package/dist/esm/reactives/EntityStore.d.ts +84 -84
  210. package/dist/esm/reactives/EntityStore.js +417 -417
  211. package/dist/esm/reactives/FakeWeakRef.d.ts +11 -11
  212. package/dist/esm/reactives/FakeWeakRef.js +14 -14
  213. package/dist/esm/sync/FileSync.d.ts +23 -23
  214. package/dist/esm/sync/FileSync.js +80 -80
  215. package/dist/esm/sync/Heartbeat.d.ts +24 -24
  216. package/dist/esm/sync/Heartbeat.js +51 -51
  217. package/dist/esm/sync/PresenceManager.d.ts +41 -41
  218. package/dist/esm/sync/PresenceManager.js +103 -103
  219. package/dist/esm/sync/PushPullSync.d.ts +36 -36
  220. package/dist/esm/sync/PushPullSync.js +137 -137
  221. package/dist/esm/sync/ServerSyncEndpointProvider.d.ts +27 -27
  222. package/dist/esm/sync/ServerSyncEndpointProvider.js +57 -57
  223. package/dist/esm/sync/Sync.d.ts +127 -127
  224. package/dist/esm/sync/Sync.js +239 -239
  225. package/dist/esm/sync/{WebsocketSync.d.ts → WebSocketSync.d.ts} +41 -41
  226. package/dist/esm/sync/{WebsocketSync.js → WebSocketSync.js} +179 -179
  227. package/dist/esm/types.d.ts +5 -5
  228. package/dist/esm/types.js +1 -1
  229. package/dist/esm/utils/Disposable.d.ts +6 -6
  230. package/dist/esm/utils/Disposable.js +14 -14
  231. package/dist/esm/utils/Resolvable.d.ts +8 -8
  232. package/dist/esm/utils/Resolvable.js +18 -18
  233. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  234. package/dist/tsconfig.tsbuildinfo +1 -1
  235. package/package.json +2 -2
  236. package/dist/cjs/AckInfoStore.d.ts +0 -10
  237. package/dist/cjs/AckInfoStore.js +0 -26
  238. package/dist/cjs/AckInfoStore.js.map +0 -1
  239. package/dist/cjs/BaselinesStore.d.ts +0 -10
  240. package/dist/cjs/BaselinesStore.js +0 -36
  241. package/dist/cjs/BaselinesStore.js.map +0 -1
  242. package/dist/cjs/Entity.d.ts +0 -96
  243. package/dist/cjs/Entity.js +0 -345
  244. package/dist/cjs/Entity.js.map +0 -1
  245. package/dist/cjs/EntityStore.d.ts +0 -36
  246. package/dist/cjs/EntityStore.js +0 -172
  247. package/dist/cjs/EntityStore.js.map +0 -1
  248. package/dist/cjs/LocalHistoryStore.d.ts +0 -15
  249. package/dist/cjs/LocalHistoryStore.js +0 -53
  250. package/dist/cjs/LocalHistoryStore.js.map +0 -1
  251. package/dist/cjs/LocalReplicaStore.d.ts +0 -13
  252. package/dist/cjs/LocalReplicaStore.js +0 -49
  253. package/dist/cjs/LocalReplicaStore.js.map +0 -1
  254. package/dist/cjs/MessageCreator.d.ts +0 -19
  255. package/dist/cjs/MessageCreator.js +0 -104
  256. package/dist/cjs/MessageCreator.js.map +0 -1
  257. package/dist/cjs/Metadata.d.ts +0 -91
  258. package/dist/cjs/Metadata.js +0 -250
  259. package/dist/cjs/Metadata.js.map +0 -1
  260. package/dist/cjs/OperationsStore.d.ts +0 -38
  261. package/dist/cjs/OperationsStore.js +0 -146
  262. package/dist/cjs/OperationsStore.js.map +0 -1
  263. package/dist/cjs/PresenceManager.d.ts +0 -30
  264. package/dist/cjs/PresenceManager.js +0 -89
  265. package/dist/cjs/PresenceManager.js.map +0 -1
  266. package/dist/cjs/Query.d.ts +0 -26
  267. package/dist/cjs/Query.js +0 -86
  268. package/dist/cjs/Query.js.map +0 -1
  269. package/dist/cjs/QueryMaker.d.ts +0 -18
  270. package/dist/cjs/QueryMaker.js +0 -98
  271. package/dist/cjs/QueryMaker.js.map +0 -1
  272. package/dist/cjs/QueryStore.d.ts +0 -38
  273. package/dist/cjs/QueryStore.js +0 -146
  274. package/dist/cjs/QueryStore.js.map +0 -1
  275. package/dist/cjs/SchemaStore.d.ts +0 -9
  276. package/dist/cjs/SchemaStore.js +0 -35
  277. package/dist/cjs/SchemaStore.js.map +0 -1
  278. package/dist/cjs/Storage.d.ts +0 -147
  279. package/dist/cjs/Storage.js +0 -346
  280. package/dist/cjs/Storage.js.map +0 -1
  281. package/dist/cjs/Sync.d.ts +0 -117
  282. package/dist/cjs/Sync.js +0 -561
  283. package/dist/cjs/Sync.js.map +0 -1
  284. package/dist/cjs/SyncHarness.d.ts +0 -45
  285. package/dist/cjs/SyncHarness.js +0 -110
  286. package/dist/cjs/SyncHarness.js.map +0 -1
  287. package/dist/cjs/metadata/LocalHistoryStore.d.ts +0 -15
  288. package/dist/cjs/metadata/LocalHistoryStore.js +0 -53
  289. package/dist/cjs/metadata/LocalHistoryStore.js.map +0 -1
  290. package/dist/cjs/queries/LiveQuery.d.ts +0 -28
  291. package/dist/cjs/queries/LiveQuery.js +0 -96
  292. package/dist/cjs/queries/LiveQuery.js.map +0 -1
  293. package/dist/cjs/queries/LiveQueryMaker.d.ts +0 -15
  294. package/dist/cjs/queries/LiveQueryMaker.js +0 -42
  295. package/dist/cjs/queries/LiveQueryMaker.js.map +0 -1
  296. package/dist/cjs/queries/LiveQueryStore.d.ts +0 -33
  297. package/dist/cjs/queries/LiveQueryStore.js +0 -85
  298. package/dist/cjs/queries/LiveQueryStore.js.map +0 -1
  299. package/dist/cjs/queries/Query.d.ts +0 -18
  300. package/dist/cjs/queries/Query.js +0 -36
  301. package/dist/cjs/queries/Query.js.map +0 -1
  302. package/dist/cjs/queries/QueryMaker.d.ts +0 -14
  303. package/dist/cjs/queries/QueryMaker.js +0 -42
  304. package/dist/cjs/queries/QueryMaker.js.map +0 -1
  305. package/dist/cjs/queries/QueryStore.d.ts +0 -35
  306. package/dist/cjs/queries/QueryStore.js +0 -130
  307. package/dist/cjs/queries/QueryStore.js.map +0 -1
  308. package/dist/cjs/queries/ranges.d.ts +0 -2
  309. package/dist/cjs/queries/ranges.js +0 -70
  310. package/dist/cjs/queries/ranges.js.map +0 -1
  311. package/dist/cjs/v2/AckInfoStore.d.ts +0 -10
  312. package/dist/cjs/v2/AckInfoStore.js +0 -26
  313. package/dist/cjs/v2/AckInfoStore.js.map +0 -1
  314. package/dist/cjs/v2/BaselinesStore.d.ts +0 -10
  315. package/dist/cjs/v2/BaselinesStore.js +0 -36
  316. package/dist/cjs/v2/BaselinesStore.js.map +0 -1
  317. package/dist/cjs/v2/DocumentManager.d.ts +0 -19
  318. package/dist/cjs/v2/DocumentManager.js +0 -47
  319. package/dist/cjs/v2/DocumentManager.js.map +0 -1
  320. package/dist/cjs/v2/Entity.d.ts +0 -87
  321. package/dist/cjs/v2/Entity.js +0 -305
  322. package/dist/cjs/v2/Entity.js.map +0 -1
  323. package/dist/cjs/v2/EntityStore.d.ts +0 -37
  324. package/dist/cjs/v2/EntityStore.js +0 -165
  325. package/dist/cjs/v2/EntityStore.js.map +0 -1
  326. package/dist/cjs/v2/IDBService.d.ts +0 -7
  327. package/dist/cjs/v2/IDBService.js +0 -26
  328. package/dist/cjs/v2/IDBService.js.map +0 -1
  329. package/dist/cjs/v2/LocalHistoryStore.d.ts +0 -15
  330. package/dist/cjs/v2/LocalHistoryStore.js +0 -53
  331. package/dist/cjs/v2/LocalHistoryStore.js.map +0 -1
  332. package/dist/cjs/v2/LocalReplicaStore.d.ts +0 -14
  333. package/dist/cjs/v2/LocalReplicaStore.js +0 -49
  334. package/dist/cjs/v2/LocalReplicaStore.js.map +0 -1
  335. package/dist/cjs/v2/MessageCreator.d.ts +0 -19
  336. package/dist/cjs/v2/MessageCreator.js +0 -99
  337. package/dist/cjs/v2/MessageCreator.js.map +0 -1
  338. package/dist/cjs/v2/Metadata.d.ts +0 -90
  339. package/dist/cjs/v2/Metadata.js +0 -251
  340. package/dist/cjs/v2/Metadata.js.map +0 -1
  341. package/dist/cjs/v2/OperationsStore.d.ts +0 -38
  342. package/dist/cjs/v2/OperationsStore.js +0 -146
  343. package/dist/cjs/v2/OperationsStore.js.map +0 -1
  344. package/dist/cjs/v2/PresenceManager.d.ts +0 -24
  345. package/dist/cjs/v2/PresenceManager.js +0 -73
  346. package/dist/cjs/v2/PresenceManager.js.map +0 -1
  347. package/dist/cjs/v2/Query.d.ts +0 -24
  348. package/dist/cjs/v2/Query.js +0 -79
  349. package/dist/cjs/v2/Query.js.map +0 -1
  350. package/dist/cjs/v2/QueryMaker.d.ts +0 -16
  351. package/dist/cjs/v2/QueryMaker.js +0 -84
  352. package/dist/cjs/v2/QueryMaker.js.map +0 -1
  353. package/dist/cjs/v2/QueryStore.d.ts +0 -26
  354. package/dist/cjs/v2/QueryStore.js +0 -136
  355. package/dist/cjs/v2/QueryStore.js.map +0 -1
  356. package/dist/cjs/v2/SchemaStore.d.ts +0 -9
  357. package/dist/cjs/v2/SchemaStore.js +0 -35
  358. package/dist/cjs/v2/SchemaStore.js.map +0 -1
  359. package/dist/cjs/v2/Storage.d.ts +0 -80
  360. package/dist/cjs/v2/Storage.js +0 -154
  361. package/dist/cjs/v2/Storage.js.map +0 -1
  362. package/dist/cjs/v2/Sync.d.ts +0 -42
  363. package/dist/cjs/v2/Sync.js +0 -98
  364. package/dist/cjs/v2/Sync.js.map +0 -1
  365. package/dist/cjs/v2/SyncHarness.d.ts +0 -45
  366. package/dist/cjs/v2/SyncHarness.js +0 -110
  367. package/dist/cjs/v2/SyncHarness.js.map +0 -1
  368. package/dist/cjs/v2/__tests__/documents.test.d.ts +0 -1
  369. package/dist/cjs/v2/__tests__/documents.test.js +0 -185
  370. package/dist/cjs/v2/__tests__/documents.test.js.map +0 -1
  371. package/dist/cjs/v2/__tests__/fixtures/testStorage.d.ts +0 -189
  372. package/dist/cjs/v2/__tests__/fixtures/testStorage.js +0 -93
  373. package/dist/cjs/v2/__tests__/fixtures/testStorage.js.map +0 -1
  374. package/dist/cjs/v2/__tests__/queries.test.d.ts +0 -1
  375. package/dist/cjs/v2/__tests__/queries.test.js +0 -92
  376. package/dist/cjs/v2/__tests__/queries.test.js.map +0 -1
  377. package/dist/cjs/v2/__tests__/setup/indexedDB.d.ts +0 -1
  378. package/dist/cjs/v2/__tests__/setup/indexedDB.js +0 -4
  379. package/dist/cjs/v2/__tests__/setup/indexedDB.js.map +0 -1
  380. package/dist/cjs/v2/constants.d.ts +0 -1
  381. package/dist/cjs/v2/constants.js +0 -5
  382. package/dist/cjs/v2/constants.js.map +0 -1
  383. package/dist/cjs/v2/idb.d.ts +0 -6
  384. package/dist/cjs/v2/idb.js +0 -71
  385. package/dist/cjs/v2/idb.js.map +0 -1
  386. package/dist/cjs/v2/index.d.ts +0 -6
  387. package/dist/cjs/v2/index.js +0 -14
  388. package/dist/cjs/v2/index.js.map +0 -1
  389. package/dist/cjs/v2/indexes.d.ts +0 -3
  390. package/dist/cjs/v2/indexes.js +0 -20
  391. package/dist/cjs/v2/indexes.js.map +0 -1
  392. package/dist/cjs/v2/openDocumentDatabase.d.ts +0 -9
  393. package/dist/cjs/v2/openDocumentDatabase.js +0 -100
  394. package/dist/cjs/v2/openDocumentDatabase.js.map +0 -1
  395. package/dist/cjs/v2/types.d.ts +0 -3
  396. package/dist/cjs/v2/types.js +0 -3
  397. package/dist/cjs/v2/types.js.map +0 -1
  398. package/dist/esm/AckInfoStore.d.ts +0 -10
  399. package/dist/esm/AckInfoStore.js +0 -22
  400. package/dist/esm/AckInfoStore.js.map +0 -1
  401. package/dist/esm/BaselinesStore.d.ts +0 -10
  402. package/dist/esm/BaselinesStore.js +0 -32
  403. package/dist/esm/BaselinesStore.js.map +0 -1
  404. package/dist/esm/Entity.d.ts +0 -96
  405. package/dist/esm/Entity.js +0 -337
  406. package/dist/esm/Entity.js.map +0 -1
  407. package/dist/esm/EntityStore.d.ts +0 -36
  408. package/dist/esm/EntityStore.js +0 -168
  409. package/dist/esm/EntityStore.js.map +0 -1
  410. package/dist/esm/LocalHistoryStore.d.ts +0 -15
  411. package/dist/esm/LocalHistoryStore.js +0 -49
  412. package/dist/esm/LocalHistoryStore.js.map +0 -1
  413. package/dist/esm/LocalReplicaStore.d.ts +0 -13
  414. package/dist/esm/LocalReplicaStore.js +0 -42
  415. package/dist/esm/LocalReplicaStore.js.map +0 -1
  416. package/dist/esm/MessageCreator.d.ts +0 -19
  417. package/dist/esm/MessageCreator.js +0 -97
  418. package/dist/esm/MessageCreator.js.map +0 -1
  419. package/dist/esm/Metadata.d.ts +0 -91
  420. package/dist/esm/Metadata.js +0 -245
  421. package/dist/esm/Metadata.js.map +0 -1
  422. package/dist/esm/OperationsStore.d.ts +0 -38
  423. package/dist/esm/OperationsStore.js +0 -142
  424. package/dist/esm/OperationsStore.js.map +0 -1
  425. package/dist/esm/PresenceManager.d.ts +0 -30
  426. package/dist/esm/PresenceManager.js +0 -85
  427. package/dist/esm/PresenceManager.js.map +0 -1
  428. package/dist/esm/Query.d.ts +0 -26
  429. package/dist/esm/Query.js +0 -82
  430. package/dist/esm/Query.js.map +0 -1
  431. package/dist/esm/QueryMaker.d.ts +0 -18
  432. package/dist/esm/QueryMaker.js +0 -94
  433. package/dist/esm/QueryMaker.js.map +0 -1
  434. package/dist/esm/QueryStore.d.ts +0 -38
  435. package/dist/esm/QueryStore.js +0 -142
  436. package/dist/esm/QueryStore.js.map +0 -1
  437. package/dist/esm/SchemaStore.d.ts +0 -9
  438. package/dist/esm/SchemaStore.js +0 -31
  439. package/dist/esm/SchemaStore.js.map +0 -1
  440. package/dist/esm/Storage.d.ts +0 -147
  441. package/dist/esm/Storage.js +0 -341
  442. package/dist/esm/Storage.js.map +0 -1
  443. package/dist/esm/Sync.d.ts +0 -117
  444. package/dist/esm/Sync.js +0 -553
  445. package/dist/esm/Sync.js.map +0 -1
  446. package/dist/esm/SyncHarness.d.ts +0 -45
  447. package/dist/esm/SyncHarness.js +0 -105
  448. package/dist/esm/SyncHarness.js.map +0 -1
  449. package/dist/esm/metadata/LocalHistoryStore.d.ts +0 -15
  450. package/dist/esm/metadata/LocalHistoryStore.js +0 -49
  451. package/dist/esm/metadata/LocalHistoryStore.js.map +0 -1
  452. package/dist/esm/queries/LiveQuery.d.ts +0 -28
  453. package/dist/esm/queries/LiveQuery.js +0 -92
  454. package/dist/esm/queries/LiveQuery.js.map +0 -1
  455. package/dist/esm/queries/LiveQueryMaker.d.ts +0 -15
  456. package/dist/esm/queries/LiveQueryMaker.js +0 -38
  457. package/dist/esm/queries/LiveQueryMaker.js.map +0 -1
  458. package/dist/esm/queries/LiveQueryStore.d.ts +0 -33
  459. package/dist/esm/queries/LiveQueryStore.js +0 -81
  460. package/dist/esm/queries/LiveQueryStore.js.map +0 -1
  461. package/dist/esm/queries/Query.d.ts +0 -18
  462. package/dist/esm/queries/Query.js +0 -32
  463. package/dist/esm/queries/Query.js.map +0 -1
  464. package/dist/esm/queries/QueryMaker.d.ts +0 -14
  465. package/dist/esm/queries/QueryMaker.js +0 -38
  466. package/dist/esm/queries/QueryMaker.js.map +0 -1
  467. package/dist/esm/queries/QueryStore.d.ts +0 -35
  468. package/dist/esm/queries/QueryStore.js +0 -126
  469. package/dist/esm/queries/QueryStore.js.map +0 -1
  470. package/dist/esm/queries/ranges.d.ts +0 -2
  471. package/dist/esm/queries/ranges.js +0 -66
  472. package/dist/esm/queries/ranges.js.map +0 -1
  473. package/dist/esm/v2/AckInfoStore.d.ts +0 -10
  474. package/dist/esm/v2/AckInfoStore.js +0 -22
  475. package/dist/esm/v2/AckInfoStore.js.map +0 -1
  476. package/dist/esm/v2/BaselinesStore.d.ts +0 -10
  477. package/dist/esm/v2/BaselinesStore.js +0 -32
  478. package/dist/esm/v2/BaselinesStore.js.map +0 -1
  479. package/dist/esm/v2/DocumentManager.d.ts +0 -19
  480. package/dist/esm/v2/DocumentManager.js +0 -43
  481. package/dist/esm/v2/DocumentManager.js.map +0 -1
  482. package/dist/esm/v2/Entity.d.ts +0 -91
  483. package/dist/esm/v2/Entity.js +0 -305
  484. package/dist/esm/v2/Entity.js.map +0 -1
  485. package/dist/esm/v2/EntityStore.d.ts +0 -37
  486. package/dist/esm/v2/EntityStore.js +0 -166
  487. package/dist/esm/v2/EntityStore.js.map +0 -1
  488. package/dist/esm/v2/IDBService.d.ts +0 -7
  489. package/dist/esm/v2/IDBService.js +0 -22
  490. package/dist/esm/v2/IDBService.js.map +0 -1
  491. package/dist/esm/v2/LocalHistoryStore.d.ts +0 -15
  492. package/dist/esm/v2/LocalHistoryStore.js +0 -49
  493. package/dist/esm/v2/LocalHistoryStore.js.map +0 -1
  494. package/dist/esm/v2/LocalReplicaStore.d.ts +0 -14
  495. package/dist/esm/v2/LocalReplicaStore.js +0 -42
  496. package/dist/esm/v2/LocalReplicaStore.js.map +0 -1
  497. package/dist/esm/v2/MessageCreator.d.ts +0 -19
  498. package/dist/esm/v2/MessageCreator.js +0 -92
  499. package/dist/esm/v2/MessageCreator.js.map +0 -1
  500. package/dist/esm/v2/Metadata.d.ts +0 -90
  501. package/dist/esm/v2/Metadata.js +0 -246
  502. package/dist/esm/v2/Metadata.js.map +0 -1
  503. package/dist/esm/v2/OperationsStore.d.ts +0 -38
  504. package/dist/esm/v2/OperationsStore.js +0 -142
  505. package/dist/esm/v2/OperationsStore.js.map +0 -1
  506. package/dist/esm/v2/PresenceManager.d.ts +0 -24
  507. package/dist/esm/v2/PresenceManager.js +0 -69
  508. package/dist/esm/v2/PresenceManager.js.map +0 -1
  509. package/dist/esm/v2/Query.d.ts +0 -24
  510. package/dist/esm/v2/Query.js +0 -75
  511. package/dist/esm/v2/Query.js.map +0 -1
  512. package/dist/esm/v2/QueryMaker.d.ts +0 -16
  513. package/dist/esm/v2/QueryMaker.js +0 -80
  514. package/dist/esm/v2/QueryMaker.js.map +0 -1
  515. package/dist/esm/v2/QueryStore.d.ts +0 -26
  516. package/dist/esm/v2/QueryStore.js +0 -132
  517. package/dist/esm/v2/QueryStore.js.map +0 -1
  518. package/dist/esm/v2/SchemaStore.d.ts +0 -9
  519. package/dist/esm/v2/SchemaStore.js +0 -31
  520. package/dist/esm/v2/SchemaStore.js.map +0 -1
  521. package/dist/esm/v2/Storage.d.ts +0 -80
  522. package/dist/esm/v2/Storage.js +0 -149
  523. package/dist/esm/v2/Storage.js.map +0 -1
  524. package/dist/esm/v2/Sync.d.ts +0 -42
  525. package/dist/esm/v2/Sync.js +0 -94
  526. package/dist/esm/v2/Sync.js.map +0 -1
  527. package/dist/esm/v2/SyncHarness.d.ts +0 -45
  528. package/dist/esm/v2/SyncHarness.js +0 -105
  529. package/dist/esm/v2/SyncHarness.js.map +0 -1
  530. package/dist/esm/v2/__tests__/documents.test.d.ts +0 -1
  531. package/dist/esm/v2/__tests__/documents.test.js +0 -208
  532. package/dist/esm/v2/__tests__/documents.test.js.map +0 -1
  533. package/dist/esm/v2/__tests__/fixtures/testStorage.d.ts +0 -223
  534. package/dist/esm/v2/__tests__/fixtures/testStorage.js +0 -106
  535. package/dist/esm/v2/__tests__/fixtures/testStorage.js.map +0 -1
  536. package/dist/esm/v2/__tests__/queries.test.d.ts +0 -1
  537. package/dist/esm/v2/__tests__/queries.test.js +0 -90
  538. package/dist/esm/v2/__tests__/queries.test.js.map +0 -1
  539. package/dist/esm/v2/__tests__/setup/indexedDB.d.ts +0 -1
  540. package/dist/esm/v2/__tests__/setup/indexedDB.js +0 -2
  541. package/dist/esm/v2/__tests__/setup/indexedDB.js.map +0 -1
  542. package/dist/esm/v2/constants.d.ts +0 -1
  543. package/dist/esm/v2/constants.js +0 -2
  544. package/dist/esm/v2/constants.js.map +0 -1
  545. package/dist/esm/v2/idb.d.ts +0 -6
  546. package/dist/esm/v2/idb.js +0 -65
  547. package/dist/esm/v2/idb.js.map +0 -1
  548. package/dist/esm/v2/index.d.ts +0 -6
  549. package/dist/esm/v2/index.js +0 -5
  550. package/dist/esm/v2/index.js.map +0 -1
  551. package/dist/esm/v2/indexes.d.ts +0 -3
  552. package/dist/esm/v2/indexes.js +0 -15
  553. package/dist/esm/v2/indexes.js.map +0 -1
  554. package/dist/esm/v2/openDocumentDatabase.d.ts +0 -9
  555. package/dist/esm/v2/openDocumentDatabase.js +0 -96
  556. package/dist/esm/v2/openDocumentDatabase.js.map +0 -1
  557. package/dist/esm/v2/types.d.ts +0 -3
  558. package/dist/esm/v2/types.js +0 -2
  559. package/dist/esm/v2/types.js.map +0 -1
  560. /package/dist/esm/sync/{WebsocketSync.js.map → WebSocketSync.js.map} +0 -0
@@ -1,422 +1,422 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EntityStore = void 0;
4
- const common_1 = require("@verdant-web/common");
5
- const utils_js_1 = require("../files/utils.js");
6
- const idb_js_1 = require("../idb.js");
7
- const DocumentFamiliyCache_js_1 = require("./DocumentFamiliyCache.js");
8
- const DEFAULT_BATCH_KEY = '@@default';
9
- class EntityStore {
10
- get log() {
11
- return this.context.log;
12
- }
13
- get db() {
14
- return this.context.documentDb;
15
- }
16
- get undoHistory() {
17
- return this.context.undoHistory;
18
- }
19
- get schema() {
20
- return this.context.schema;
21
- }
22
- constructor({ context, meta, batchTimeout = 200, files, }) {
23
- this.documentFamilyCaches = new Map();
24
- this.unsubscribes = [];
25
- this._disposed = false;
26
- this.currentBatchKey = DEFAULT_BATCH_KEY;
27
- this.setContext = (context) => {
28
- this.context = context;
29
- };
30
- this.getDocumentSchema = (oid) => {
31
- const { collection } = (0, common_1.decomposeOid)(oid);
32
- if (!this.schema.collections[collection]) {
33
- this.log('warn', `Missing schema for collection: ${collection}`);
34
- return null;
35
- }
36
- return {
37
- type: 'object',
38
- properties: this.schema.collections[collection].fields,
39
- };
40
- };
41
- this.resetFamilyCache = async (familyCache) => {
42
- // avoid writing to disposed db
43
- if (this._disposed)
44
- return;
45
- // metadata must be loaded from database to initialize family cache
46
- const transaction = this.meta.createTransaction([
47
- 'baselines',
48
- 'operations',
49
- ]);
50
- const baselines = [];
51
- const operations = [];
52
- await Promise.all([
53
- this.meta.baselines.iterateOverAllForDocument(familyCache.oid, (baseline) => {
54
- baselines.push(baseline);
55
- }, {
56
- transaction,
57
- }),
58
- this.meta.operations.iterateOverAllOperationsForDocument(familyCache.oid, (op) => operations.push(op), { transaction }),
59
- ]);
60
- familyCache.reset(operations, baselines);
61
- };
62
- this.openFamilyCache = async (oid) => {
63
- const documentOid = (0, common_1.getOidRoot)(oid);
64
- let familyCache = this.documentFamilyCaches.get(documentOid);
65
- if (!familyCache) {
66
- // metadata must be loaded from database to initialize family cache
67
- familyCache = new DocumentFamiliyCache_js_1.DocumentFamilyCache({
68
- oid: documentOid,
69
- store: this,
70
- context: this.context,
71
- });
72
- await this.resetFamilyCache(familyCache);
73
- this.unsubscribes.push(familyCache.subscribe('change:*', this.onEntityChange));
74
- this.documentFamilyCaches.set(documentOid, familyCache);
75
- // TODO: cleanup cache when all documents are disposed
76
- }
77
- return familyCache;
78
- };
79
- this.onEntityChange = async (oid) => {
80
- // queueMicrotask(() => this.writeDocumentToStorage(oid));
81
- };
82
- this.writeDocumentToStorage = async (oid) => {
83
- if (this._disposed) {
84
- this.log('warn', 'EntityStore is disposed, not writing to storage');
85
- return;
86
- }
87
- const rootOid = (0, common_1.getOidRoot)(oid);
88
- const { id, collection } = (0, common_1.decomposeOid)(rootOid);
89
- const entity = await this.get(rootOid);
90
- if (this._disposed) {
91
- this.log('warn', 'EntityStore is disposed, not writing to storage');
92
- return;
93
- }
94
- const snapshot = entity === null || entity === void 0 ? void 0 : entity.getSnapshot();
95
- if (snapshot) {
96
- const stored = (0, common_1.cloneDeep)(snapshot);
97
- (0, common_1.assignIndexValues)(this.schema.collections[collection], stored);
98
- // IMPORTANT! this property must be assigned
99
- (0, common_1.assignOidPropertiesToAllSubObjects)(stored);
100
- try {
101
- const tx = this.db.transaction(collection, 'readwrite');
102
- const store = tx.objectStore(collection);
103
- await (0, idb_js_1.storeRequestPromise)(store.put(stored));
104
- this.log('info', '📝', 'wrote', collection, id, 'to storage');
105
- }
106
- catch (err) {
107
- // if the document can't be written, something's very wrong :(
108
- // log the error and move on...
109
- this.log("⚠️ CRITICAL: possibly corrupt data couldn't be written to queryable storage. This is probably a bug in verdant! Please report at https://github.com/a-type/verdant/issues", '\n', 'Invalid data:', JSON.stringify(stored));
110
- }
111
- }
112
- else {
113
- const tx = this.db.transaction(collection, 'readwrite');
114
- const store = tx.objectStore(collection);
115
- await (0, idb_js_1.storeRequestPromise)(store.delete(id));
116
- this.log('info', '❌', 'deleted', collection, id, 'from storage');
117
- }
118
- };
119
- this.get = async (oid) => {
120
- const familyCache = await this.openFamilyCache(oid);
121
- const schema = this.getDocumentSchema(oid);
122
- if (!schema) {
123
- return null;
124
- }
125
- return familyCache.getEntity(oid, schema);
126
- };
127
- /**
128
- * Advanced usage!
129
- * Immediately returns an entity if it exists in the memory cache. An
130
- * entity would be cached if it has been retrieved by a live query.
131
- */
132
- this.getCached = (oid) => {
133
- const cache = this.documentFamilyCaches.get(oid);
134
- if (cache) {
135
- const schema = this.getDocumentSchema(oid);
136
- if (!schema) {
137
- return null;
138
- }
139
- return cache.getEntity(oid, schema);
140
- }
141
- return null;
142
- };
143
- /**
144
- * Creates a new document and returns an Entity for it. The created
145
- * document is submitted to storage and sync.
146
- */
147
- this.create = async (initial, oid, options) => {
148
- // remove all OID associations from initial data
149
- (0, common_1.removeOidsFromAllSubObjects)(initial);
150
- // first grab any file and replace them with refs
151
- const processed = (0, utils_js_1.processValueFiles)(initial, this.files.add);
152
- (0, common_1.assignOid)(processed, oid);
153
- const operations = this.meta.patchCreator.createInitialize(processed, oid);
154
- const familyCache = await this.openFamilyCache(oid);
155
- familyCache.insertUnconfirmedOperations(operations);
156
- // don't enqueue these, submit as distinct operation.
157
- // we do this so it can be immediately queryable from storage...
158
- // only holding it in memory would introduce lag before it shows up
159
- // in other queries.
160
- await this.submitOperations(operations, options);
161
- const schema = this.getDocumentSchema(oid);
162
- if (!schema) {
163
- throw new Error(`Cannot create a document in the ${(0, common_1.decomposeOid)(oid).collection} collection; it is not defined in the current schema version.`);
164
- }
165
- return familyCache.getEntity(oid, schema);
166
- };
167
- this.addOperationsToOpenCaches = async (operations, confirmed = true, info) => {
168
- const operationsByOid = (0, common_1.groupPatchesByRootOid)(operations);
169
- const oids = Object.keys(operationsByOid);
170
- oids.forEach((oid) => {
171
- const familyCache = this.documentFamilyCaches.get(oid);
172
- if (familyCache) {
173
- this.log('adding', confirmed ? 'confirmed' : 'unconfirmed', 'operations to cache', oid, operationsByOid[oid].length);
174
- if (confirmed) {
175
- familyCache.insertOperations(operationsByOid[oid], info);
176
- }
177
- else {
178
- familyCache.insertUnconfirmedOperations(operationsByOid[oid]);
179
- }
180
- }
181
- });
182
- };
183
- this.addBaselinesToCaches = async (baselines, info) => {
184
- const baselinesByOid = (0, common_1.groupBaselinesByRootOid)(baselines);
185
- const oids = Object.keys(baselinesByOid);
186
- const caches = await Promise.all(oids.map((oid) => this.openFamilyCache(oid)));
187
- oids.forEach((oid, i) => {
188
- const familyCache = caches[i];
189
- if (familyCache) {
190
- familyCache.insertBaselines(baselinesByOid[oid], info);
191
- }
192
- });
193
- };
194
- this.addDataToOpenCaches = ({ baselines, operations, reset, isLocal, }) => {
195
- const baselinesByDocumentOid = (0, common_1.groupBaselinesByRootOid)(baselines);
196
- const operationsByDocumentOid = (0, common_1.groupPatchesByRootOid)(operations);
197
- const allDocumentOids = Array.from(new Set(Object.keys(baselinesByDocumentOid).concat(Object.keys(operationsByDocumentOid))));
198
- for (const oid of allDocumentOids) {
199
- const familyCache = this.documentFamilyCaches.get(oid);
200
- if (familyCache) {
201
- familyCache.addConfirmedData({
202
- operations: operationsByDocumentOid[oid] || [],
203
- baselines: baselinesByDocumentOid[oid] || [],
204
- reset,
205
- isLocal,
206
- });
207
- this.log('debug', 'Added data to cache for', oid);
208
- }
209
- else {
210
- this.log('debug', 'Could not add data to cache for', oid, 'because it is not open');
211
- }
212
- }
213
- return allDocumentOids;
214
- };
215
- this.addData = async ({ operations, baselines, reset, }) => {
216
- // first, synchronously add data to any open caches for immediate change propagation
217
- const allDocumentOids = this.addDataToOpenCaches({
218
- operations,
219
- baselines,
220
- reset,
221
- });
222
- // then, asynchronously add data to storage
223
- if (reset) {
224
- this.log('Resetting local store to replicate remote synced data', baselines.length, 'baselines, and', operations.length, 'operations');
225
- await this.meta.reset();
226
- await this.resetStoredDocuments();
227
- }
228
- await this.meta.insertRemoteBaselines(baselines);
229
- await this.meta.insertRemoteOperations(operations);
230
- if (reset) {
231
- await this.resetAllCaches();
232
- }
233
- // recompute all affected documents for querying
234
- for (const oid of allDocumentOids) {
235
- await this.writeDocumentToStorage(oid);
236
- }
237
- // notify active queries
238
- const affectedCollections = new Set(allDocumentOids.map((oid) => (0, common_1.decomposeOid)(oid).collection));
239
- this.context.log('changes to collections', affectedCollections);
240
- this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
241
- };
242
- this.addLocalOperations = async (operations) => {
243
- this.log('Adding local operations', operations.length);
244
- this.addOperationsToOpenCaches(operations, false, { isLocal: true });
245
- this.operationBatcher.add({
246
- key: this.currentBatchKey,
247
- items: operations,
248
- });
249
- };
250
- this.batch = ({ undoable = true, batchName = (0, common_1.generateId)(), max = null, timeout = this.defaultBatchTimeout, } = {}) => {
251
- const internalBatch = this.operationBatcher.add({
252
- key: batchName,
253
- max,
254
- timeout,
255
- items: [],
256
- userData: { undoable },
257
- });
258
- const externalApi = {
259
- run: (fn) => {
260
- // while the provided function runs, operations are forwarded
261
- // to the new batch instead of default. this relies on the function
262
- // being synchronous.
263
- this.currentBatchKey = batchName;
264
- fn();
265
- this.currentBatchKey = DEFAULT_BATCH_KEY;
266
- return externalApi;
267
- },
268
- flush: async () => {
269
- // before running a batch, the default operations must be flushed
270
- // this better preserves undo history behavior...
271
- // if we left the default batch open while flushing a named batch,
272
- // then the default batch would be flushed after the named batch,
273
- // and the default batch could contain operations both prior and
274
- // after the named batch. this would result in a confusing undo
275
- // history where the first undo might reverse changes before and
276
- // after a set of other changes.
277
- await this.operationBatcher.flush(DEFAULT_BATCH_KEY);
278
- return internalBatch.flush();
279
- },
280
- discard: () => {
281
- this.operationBatcher.discard(batchName);
282
- },
283
- };
284
- return externalApi;
285
- };
286
- /**
287
- * @deprecated use `batch` instead
288
- */
289
- this.flushPatches = async () => {
290
- await this.operationBatcher.flush(this.currentBatchKey);
291
- };
292
- this.flushOperations = async (operations, batchKey, meta) => {
293
- if (!operations.length)
294
- return;
295
- this.log('Flushing operations', operations.length, 'to storage / sync');
296
- // rewrite timestamps of all operations to now - this preserves
297
- // the linear history of operations which are sent to the server.
298
- // even if multiple batches are spun up in parallel and flushed
299
- // after delay, the final operations in each one should reflect
300
- // when the batch flushed, not when the changes were made.
301
- // This also corresponds to user-observed behavior, since unconfirmed
302
- // operations are applied universally after confirmed operations locally,
303
- // so even operations which were made before a remote operation but
304
- // have not been confirmed yet will appear to come after the remote one
305
- // despite the provisional timestamp being earlier (see DocumentFamilyCache#computeView)
306
- for (const op of operations) {
307
- op.timestamp = this.meta.now;
308
- }
309
- await this.submitOperations(operations, meta);
310
- };
311
- this.submitOperations = async (operations, { undoable = true } = {}) => {
312
- if (undoable) {
313
- // FIXME: this is too slow and needs to be optimized.
314
- this.undoHistory.addUndo(await this.createUndo(operations));
315
- }
316
- await this.meta.insertLocalOperation(operations);
317
- // recompute all affected documents for querying
318
- const allDocumentOids = Array.from(new Set(operations.map((op) => (0, common_1.getOidRoot)(op.oid))));
319
- // confirm the operations
320
- this.addDataToOpenCaches({ operations, baselines: [], isLocal: true });
321
- for (const oid of allDocumentOids) {
322
- await this.writeDocumentToStorage(oid);
323
- }
324
- // TODO: find a more efficient and straightforward way to update affected
325
- // queries. Move to Metadata?
326
- const affectedCollections = new Set(operations.map(({ oid }) => (0, common_1.decomposeOid)(oid).collection));
327
- this.context.log('changes to collections', affectedCollections);
328
- this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
329
- };
330
- this.getInverseOperations = async (ops) => {
331
- const grouped = (0, common_1.groupPatchesByIdentifier)(ops);
332
- const inverseOps = [];
333
- const getNow = () => this.meta.now;
334
- for (const [oid, patches] of Object.entries(grouped)) {
335
- const familyCache = await this.openFamilyCache(oid);
336
- let { view, deleted } = familyCache.computeConfirmedView(oid);
337
- const inverse = (0, common_1.getUndoOperations)(oid, view, patches, getNow);
338
- inverseOps.unshift(...inverse);
339
- }
340
- return inverseOps;
341
- };
342
- this.createUndo = async (ops) => {
343
- const inverseOps = await this.getInverseOperations(ops);
344
- return async () => {
345
- const redo = await this.createUndo(inverseOps);
346
- await this.submitOperations(inverseOps.map((op) => {
347
- op.timestamp = this.meta.now;
348
- return op;
349
- }),
350
- // undos should not generate their own undo operations
351
- // since they already calculate redo as the inverse.
352
- { undoable: false });
353
- return redo;
354
- };
355
- };
356
- this.delete = async (oid, options) => {
357
- (0, common_1.assert)(oid === (0, common_1.getOidRoot)(oid), 'Only root documents may be deleted via client methods');
358
- // we need to get all sub-object oids to delete alongside the root
359
- const allOids = await this.meta.getAllDocumentRelatedOids(oid);
360
- const patches = this.meta.patchCreator.createDeleteAll(allOids);
361
- // don't enqueue these, submit as distinct operation
362
- await this.submitOperations(patches, options);
363
- };
364
- this.deleteAll = async (oids, options) => {
365
- const allOids = await Promise.all(oids.map((oid) => this.meta.getAllDocumentRelatedOids(oid)));
366
- const patches = this.meta.patchCreator.createDeleteAll(allOids.flat());
367
- // don't enqueue these, submit as distinct operation
368
- await this.submitOperations(patches, options);
369
- };
370
- this.reset = async () => {
371
- this.context.log('warn', 'Resetting local database');
372
- await this.resetStoredDocuments();
373
- await this.resetAllCaches();
374
- // this.context.entityEvents.emit(
375
- // 'collectionsChanged',
376
- // Object.keys(this.schema.collections),
377
- // );
378
- };
379
- this.destroy = () => {
380
- this._disposed = true;
381
- for (const unsubscribe of this.unsubscribes) {
382
- unsubscribe();
383
- }
384
- for (const cache of this.documentFamilyCaches.values()) {
385
- cache.dispose();
386
- }
387
- this.documentFamilyCaches.clear();
388
- };
389
- this.handleRebase = (baselines) => {
390
- this.log('debug', 'Reacting to rebases', baselines.length);
391
- this.addBaselinesToCaches(baselines, { isLocal: true });
392
- };
393
- this.resetStoredDocuments = async () => {
394
- const tx = this.db.transaction(Object.keys(this.schema.collections), 'readwrite');
395
- for (const collection of Object.keys(this.schema.collections)) {
396
- const store = tx.objectStore(collection);
397
- await (0, idb_js_1.storeRequestPromise)(store.clear());
398
- }
399
- };
400
- this.resetAllCaches = async () => {
401
- for (const [_, cache] of this.documentFamilyCaches) {
402
- await this.resetFamilyCache(cache);
403
- }
404
- };
405
- this.context = context;
406
- this.defaultBatchTimeout = batchTimeout;
407
- this.meta = meta;
408
- this.files = files;
409
- this.operationBatcher = new common_1.Batcher(this.flushOperations);
410
- // initialize default batch
411
- this.operationBatcher.add({
412
- key: DEFAULT_BATCH_KEY,
413
- items: [],
414
- max: 100,
415
- timeout: batchTimeout,
416
- userData: { undoable: true },
417
- });
418
- this.unsubscribes.push(this.meta.subscribe('rebase', this.handleRebase));
419
- }
420
- }
421
- exports.EntityStore = EntityStore;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityStore = void 0;
4
+ const common_1 = require("@verdant-web/common");
5
+ const utils_js_1 = require("../files/utils.js");
6
+ const idb_js_1 = require("../idb.js");
7
+ const DocumentFamiliyCache_js_1 = require("./DocumentFamiliyCache.js");
8
+ const DEFAULT_BATCH_KEY = '@@default';
9
+ class EntityStore {
10
+ get log() {
11
+ return this.context.log;
12
+ }
13
+ get db() {
14
+ return this.context.documentDb;
15
+ }
16
+ get undoHistory() {
17
+ return this.context.undoHistory;
18
+ }
19
+ get schema() {
20
+ return this.context.schema;
21
+ }
22
+ constructor({ context, meta, batchTimeout = 200, files, }) {
23
+ this.documentFamilyCaches = new Map();
24
+ this.unsubscribes = [];
25
+ this._disposed = false;
26
+ this.currentBatchKey = DEFAULT_BATCH_KEY;
27
+ this.setContext = (context) => {
28
+ this.context = context;
29
+ };
30
+ this.getDocumentSchema = (oid) => {
31
+ const { collection } = (0, common_1.decomposeOid)(oid);
32
+ if (!this.schema.collections[collection]) {
33
+ this.log('warn', `Missing schema for collection: ${collection}`);
34
+ return null;
35
+ }
36
+ return {
37
+ type: 'object',
38
+ properties: this.schema.collections[collection].fields,
39
+ };
40
+ };
41
+ this.resetFamilyCache = async (familyCache) => {
42
+ // avoid writing to disposed db
43
+ if (this._disposed)
44
+ return;
45
+ // metadata must be loaded from database to initialize family cache
46
+ const transaction = this.meta.createTransaction([
47
+ 'baselines',
48
+ 'operations',
49
+ ]);
50
+ const baselines = [];
51
+ const operations = [];
52
+ await Promise.all([
53
+ this.meta.baselines.iterateOverAllForDocument(familyCache.oid, (baseline) => {
54
+ baselines.push(baseline);
55
+ }, {
56
+ transaction,
57
+ }),
58
+ this.meta.operations.iterateOverAllOperationsForDocument(familyCache.oid, (op) => operations.push(op), { transaction }),
59
+ ]);
60
+ familyCache.reset(operations, baselines);
61
+ };
62
+ this.openFamilyCache = async (oid) => {
63
+ const documentOid = (0, common_1.getOidRoot)(oid);
64
+ let familyCache = this.documentFamilyCaches.get(documentOid);
65
+ if (!familyCache) {
66
+ // metadata must be loaded from database to initialize family cache
67
+ familyCache = new DocumentFamiliyCache_js_1.DocumentFamilyCache({
68
+ oid: documentOid,
69
+ store: this,
70
+ context: this.context,
71
+ });
72
+ await this.resetFamilyCache(familyCache);
73
+ this.unsubscribes.push(familyCache.subscribe('change:*', this.onEntityChange));
74
+ this.documentFamilyCaches.set(documentOid, familyCache);
75
+ // TODO: cleanup cache when all documents are disposed
76
+ }
77
+ return familyCache;
78
+ };
79
+ this.onEntityChange = async (oid) => {
80
+ // queueMicrotask(() => this.writeDocumentToStorage(oid));
81
+ };
82
+ this.writeDocumentToStorage = async (oid) => {
83
+ if (this._disposed) {
84
+ this.log('warn', 'EntityStore is disposed, not writing to storage');
85
+ return;
86
+ }
87
+ const rootOid = (0, common_1.getOidRoot)(oid);
88
+ const { id, collection } = (0, common_1.decomposeOid)(rootOid);
89
+ const entity = await this.get(rootOid);
90
+ if (this._disposed) {
91
+ this.log('warn', 'EntityStore is disposed, not writing to storage');
92
+ return;
93
+ }
94
+ const snapshot = entity === null || entity === void 0 ? void 0 : entity.getSnapshot();
95
+ if (snapshot) {
96
+ const stored = (0, common_1.cloneDeep)(snapshot);
97
+ (0, common_1.assignIndexValues)(this.schema.collections[collection], stored);
98
+ // IMPORTANT! this property must be assigned
99
+ (0, common_1.assignOidPropertiesToAllSubObjects)(stored);
100
+ try {
101
+ const tx = this.db.transaction(collection, 'readwrite');
102
+ const store = tx.objectStore(collection);
103
+ await (0, idb_js_1.storeRequestPromise)(store.put(stored));
104
+ this.log('info', '📝', 'wrote', collection, id, 'to storage');
105
+ }
106
+ catch (err) {
107
+ // if the document can't be written, something's very wrong :(
108
+ // log the error and move on...
109
+ this.log("⚠️ CRITICAL: possibly corrupt data couldn't be written to queryable storage. This is probably a bug in verdant! Please report at https://github.com/a-type/verdant/issues", '\n', 'Invalid data:', JSON.stringify(stored));
110
+ }
111
+ }
112
+ else {
113
+ const tx = this.db.transaction(collection, 'readwrite');
114
+ const store = tx.objectStore(collection);
115
+ await (0, idb_js_1.storeRequestPromise)(store.delete(id));
116
+ this.log('info', '❌', 'deleted', collection, id, 'from storage');
117
+ }
118
+ };
119
+ this.get = async (oid) => {
120
+ const familyCache = await this.openFamilyCache(oid);
121
+ const schema = this.getDocumentSchema(oid);
122
+ if (!schema) {
123
+ return null;
124
+ }
125
+ return familyCache.getEntity(oid, schema);
126
+ };
127
+ /**
128
+ * Advanced usage!
129
+ * Immediately returns an entity if it exists in the memory cache. An
130
+ * entity would be cached if it has been retrieved by a live query.
131
+ */
132
+ this.getCached = (oid) => {
133
+ const cache = this.documentFamilyCaches.get(oid);
134
+ if (cache) {
135
+ const schema = this.getDocumentSchema(oid);
136
+ if (!schema) {
137
+ return null;
138
+ }
139
+ return cache.getEntity(oid, schema);
140
+ }
141
+ return null;
142
+ };
143
+ /**
144
+ * Creates a new document and returns an Entity for it. The created
145
+ * document is submitted to storage and sync.
146
+ */
147
+ this.create = async (initial, oid, options) => {
148
+ // remove all OID associations from initial data
149
+ (0, common_1.removeOidsFromAllSubObjects)(initial);
150
+ // first grab any file and replace them with refs
151
+ const processed = (0, utils_js_1.processValueFiles)(initial, this.files.add);
152
+ (0, common_1.assignOid)(processed, oid);
153
+ const operations = this.meta.patchCreator.createInitialize(processed, oid);
154
+ const familyCache = await this.openFamilyCache(oid);
155
+ familyCache.insertUnconfirmedOperations(operations);
156
+ // don't enqueue these, submit as distinct operation.
157
+ // we do this so it can be immediately queryable from storage...
158
+ // only holding it in memory would introduce lag before it shows up
159
+ // in other queries.
160
+ await this.submitOperations(operations, options);
161
+ const schema = this.getDocumentSchema(oid);
162
+ if (!schema) {
163
+ throw new Error(`Cannot create a document in the ${(0, common_1.decomposeOid)(oid).collection} collection; it is not defined in the current schema version.`);
164
+ }
165
+ return familyCache.getEntity(oid, schema);
166
+ };
167
+ this.addOperationsToOpenCaches = async (operations, confirmed = true, info) => {
168
+ const operationsByOid = (0, common_1.groupPatchesByRootOid)(operations);
169
+ const oids = Object.keys(operationsByOid);
170
+ oids.forEach((oid) => {
171
+ const familyCache = this.documentFamilyCaches.get(oid);
172
+ if (familyCache) {
173
+ this.log('adding', confirmed ? 'confirmed' : 'unconfirmed', 'operations to cache', oid, operationsByOid[oid].length);
174
+ if (confirmed) {
175
+ familyCache.insertOperations(operationsByOid[oid], info);
176
+ }
177
+ else {
178
+ familyCache.insertUnconfirmedOperations(operationsByOid[oid]);
179
+ }
180
+ }
181
+ });
182
+ };
183
+ this.addBaselinesToCaches = async (baselines, info) => {
184
+ const baselinesByOid = (0, common_1.groupBaselinesByRootOid)(baselines);
185
+ const oids = Object.keys(baselinesByOid);
186
+ const caches = await Promise.all(oids.map((oid) => this.openFamilyCache(oid)));
187
+ oids.forEach((oid, i) => {
188
+ const familyCache = caches[i];
189
+ if (familyCache) {
190
+ familyCache.insertBaselines(baselinesByOid[oid], info);
191
+ }
192
+ });
193
+ };
194
+ this.addDataToOpenCaches = ({ baselines, operations, reset, isLocal, }) => {
195
+ const baselinesByDocumentOid = (0, common_1.groupBaselinesByRootOid)(baselines);
196
+ const operationsByDocumentOid = (0, common_1.groupPatchesByRootOid)(operations);
197
+ const allDocumentOids = Array.from(new Set(Object.keys(baselinesByDocumentOid).concat(Object.keys(operationsByDocumentOid))));
198
+ for (const oid of allDocumentOids) {
199
+ const familyCache = this.documentFamilyCaches.get(oid);
200
+ if (familyCache) {
201
+ familyCache.addConfirmedData({
202
+ operations: operationsByDocumentOid[oid] || [],
203
+ baselines: baselinesByDocumentOid[oid] || [],
204
+ reset,
205
+ isLocal,
206
+ });
207
+ this.log('debug', 'Added data to cache for', oid);
208
+ }
209
+ else {
210
+ this.log('debug', 'Could not add data to cache for', oid, 'because it is not open');
211
+ }
212
+ }
213
+ return allDocumentOids;
214
+ };
215
+ this.addData = async ({ operations, baselines, reset, }) => {
216
+ // first, synchronously add data to any open caches for immediate change propagation
217
+ const allDocumentOids = this.addDataToOpenCaches({
218
+ operations,
219
+ baselines,
220
+ reset,
221
+ });
222
+ // then, asynchronously add data to storage
223
+ if (reset) {
224
+ this.log('Resetting local store to replicate remote synced data', baselines.length, 'baselines, and', operations.length, 'operations');
225
+ await this.meta.reset();
226
+ await this.resetStoredDocuments();
227
+ }
228
+ await this.meta.insertRemoteBaselines(baselines);
229
+ await this.meta.insertRemoteOperations(operations);
230
+ if (reset) {
231
+ await this.resetAllCaches();
232
+ }
233
+ // recompute all affected documents for querying
234
+ for (const oid of allDocumentOids) {
235
+ await this.writeDocumentToStorage(oid);
236
+ }
237
+ // notify active queries
238
+ const affectedCollections = new Set(allDocumentOids.map((oid) => (0, common_1.decomposeOid)(oid).collection));
239
+ this.context.log('changes to collections', affectedCollections);
240
+ this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
241
+ };
242
+ this.addLocalOperations = async (operations) => {
243
+ this.log('Adding local operations', operations.length);
244
+ this.addOperationsToOpenCaches(operations, false, { isLocal: true });
245
+ this.operationBatcher.add({
246
+ key: this.currentBatchKey,
247
+ items: operations,
248
+ });
249
+ };
250
+ this.batch = ({ undoable = true, batchName = (0, common_1.generateId)(), max = null, timeout = this.defaultBatchTimeout, } = {}) => {
251
+ const internalBatch = this.operationBatcher.add({
252
+ key: batchName,
253
+ max,
254
+ timeout,
255
+ items: [],
256
+ userData: { undoable },
257
+ });
258
+ const externalApi = {
259
+ run: (fn) => {
260
+ // while the provided function runs, operations are forwarded
261
+ // to the new batch instead of default. this relies on the function
262
+ // being synchronous.
263
+ this.currentBatchKey = batchName;
264
+ fn();
265
+ this.currentBatchKey = DEFAULT_BATCH_KEY;
266
+ return externalApi;
267
+ },
268
+ flush: async () => {
269
+ // before running a batch, the default operations must be flushed
270
+ // this better preserves undo history behavior...
271
+ // if we left the default batch open while flushing a named batch,
272
+ // then the default batch would be flushed after the named batch,
273
+ // and the default batch could contain operations both prior and
274
+ // after the named batch. this would result in a confusing undo
275
+ // history where the first undo might reverse changes before and
276
+ // after a set of other changes.
277
+ await this.operationBatcher.flush(DEFAULT_BATCH_KEY);
278
+ return internalBatch.flush();
279
+ },
280
+ discard: () => {
281
+ this.operationBatcher.discard(batchName);
282
+ },
283
+ };
284
+ return externalApi;
285
+ };
286
+ /**
287
+ * @deprecated use `batch` instead
288
+ */
289
+ this.flushPatches = async () => {
290
+ await this.operationBatcher.flush(this.currentBatchKey);
291
+ };
292
+ this.flushOperations = async (operations, batchKey, meta) => {
293
+ if (!operations.length)
294
+ return;
295
+ this.log('Flushing operations', operations.length, 'to storage / sync');
296
+ // rewrite timestamps of all operations to now - this preserves
297
+ // the linear history of operations which are sent to the server.
298
+ // even if multiple batches are spun up in parallel and flushed
299
+ // after delay, the final operations in each one should reflect
300
+ // when the batch flushed, not when the changes were made.
301
+ // This also corresponds to user-observed behavior, since unconfirmed
302
+ // operations are applied universally after confirmed operations locally,
303
+ // so even operations which were made before a remote operation but
304
+ // have not been confirmed yet will appear to come after the remote one
305
+ // despite the provisional timestamp being earlier (see DocumentFamilyCache#computeView)
306
+ for (const op of operations) {
307
+ op.timestamp = this.meta.now;
308
+ }
309
+ await this.submitOperations(operations, meta);
310
+ };
311
+ this.submitOperations = async (operations, { undoable = true } = {}) => {
312
+ if (undoable) {
313
+ // FIXME: this is too slow and needs to be optimized.
314
+ this.undoHistory.addUndo(await this.createUndo(operations));
315
+ }
316
+ await this.meta.insertLocalOperation(operations);
317
+ // recompute all affected documents for querying
318
+ const allDocumentOids = Array.from(new Set(operations.map((op) => (0, common_1.getOidRoot)(op.oid))));
319
+ // confirm the operations
320
+ this.addDataToOpenCaches({ operations, baselines: [], isLocal: true });
321
+ for (const oid of allDocumentOids) {
322
+ await this.writeDocumentToStorage(oid);
323
+ }
324
+ // TODO: find a more efficient and straightforward way to update affected
325
+ // queries. Move to Metadata?
326
+ const affectedCollections = new Set(operations.map(({ oid }) => (0, common_1.decomposeOid)(oid).collection));
327
+ this.context.log('changes to collections', affectedCollections);
328
+ this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
329
+ };
330
+ this.getInverseOperations = async (ops) => {
331
+ const grouped = (0, common_1.groupPatchesByIdentifier)(ops);
332
+ const inverseOps = [];
333
+ const getNow = () => this.meta.now;
334
+ for (const [oid, patches] of Object.entries(grouped)) {
335
+ const familyCache = await this.openFamilyCache(oid);
336
+ let { view, deleted } = familyCache.computeConfirmedView(oid);
337
+ const inverse = (0, common_1.getUndoOperations)(oid, view, patches, getNow);
338
+ inverseOps.unshift(...inverse);
339
+ }
340
+ return inverseOps;
341
+ };
342
+ this.createUndo = async (ops) => {
343
+ const inverseOps = await this.getInverseOperations(ops);
344
+ return async () => {
345
+ const redo = await this.createUndo(inverseOps);
346
+ await this.submitOperations(inverseOps.map((op) => {
347
+ op.timestamp = this.meta.now;
348
+ return op;
349
+ }),
350
+ // undos should not generate their own undo operations
351
+ // since they already calculate redo as the inverse.
352
+ { undoable: false });
353
+ return redo;
354
+ };
355
+ };
356
+ this.delete = async (oid, options) => {
357
+ (0, common_1.assert)(oid === (0, common_1.getOidRoot)(oid), 'Only root documents may be deleted via client methods');
358
+ // we need to get all sub-object oids to delete alongside the root
359
+ const allOids = await this.meta.getAllDocumentRelatedOids(oid);
360
+ const patches = this.meta.patchCreator.createDeleteAll(allOids);
361
+ // don't enqueue these, submit as distinct operation
362
+ await this.submitOperations(patches, options);
363
+ };
364
+ this.deleteAll = async (oids, options) => {
365
+ const allOids = await Promise.all(oids.map((oid) => this.meta.getAllDocumentRelatedOids(oid)));
366
+ const patches = this.meta.patchCreator.createDeleteAll(allOids.flat());
367
+ // don't enqueue these, submit as distinct operation
368
+ await this.submitOperations(patches, options);
369
+ };
370
+ this.reset = async () => {
371
+ this.context.log('warn', 'Resetting local database');
372
+ await this.resetStoredDocuments();
373
+ await this.resetAllCaches();
374
+ // this.context.entityEvents.emit(
375
+ // 'collectionsChanged',
376
+ // Object.keys(this.schema.collections),
377
+ // );
378
+ };
379
+ this.destroy = () => {
380
+ this._disposed = true;
381
+ for (const unsubscribe of this.unsubscribes) {
382
+ unsubscribe();
383
+ }
384
+ for (const cache of this.documentFamilyCaches.values()) {
385
+ cache.dispose();
386
+ }
387
+ this.documentFamilyCaches.clear();
388
+ };
389
+ this.handleRebase = (baselines) => {
390
+ this.log('debug', 'Reacting to rebases', baselines.length);
391
+ this.addBaselinesToCaches(baselines, { isLocal: true });
392
+ };
393
+ this.resetStoredDocuments = async () => {
394
+ const tx = this.db.transaction(Object.keys(this.schema.collections), 'readwrite');
395
+ for (const collection of Object.keys(this.schema.collections)) {
396
+ const store = tx.objectStore(collection);
397
+ await (0, idb_js_1.storeRequestPromise)(store.clear());
398
+ }
399
+ };
400
+ this.resetAllCaches = async () => {
401
+ for (const [_, cache] of this.documentFamilyCaches) {
402
+ await this.resetFamilyCache(cache);
403
+ }
404
+ };
405
+ this.context = context;
406
+ this.defaultBatchTimeout = batchTimeout;
407
+ this.meta = meta;
408
+ this.files = files;
409
+ this.operationBatcher = new common_1.Batcher(this.flushOperations);
410
+ // initialize default batch
411
+ this.operationBatcher.add({
412
+ key: DEFAULT_BATCH_KEY,
413
+ items: [],
414
+ max: 100,
415
+ timeout: batchTimeout,
416
+ userData: { undoable: true },
417
+ });
418
+ this.unsubscribes.push(this.meta.subscribe('rebase', this.handleRebase));
419
+ }
420
+ }
421
+ exports.EntityStore = EntityStore;
422
422
  //# sourceMappingURL=EntityStore.js.map