@verdant-web/store 2.7.5 → 2.7.7-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (717) hide show
  1. package/dist/bundle/index.js +9 -9
  2. package/dist/bundle/index.js.map +4 -4
  3. package/dist/cjs/AckInfoStore.d.ts +10 -0
  4. package/dist/cjs/AckInfoStore.js +26 -0
  5. package/dist/cjs/AckInfoStore.js.map +1 -0
  6. package/dist/cjs/BackoffScheduler.d.ts +19 -19
  7. package/dist/cjs/BackoffScheduler.js +44 -44
  8. package/dist/cjs/BaselinesStore.d.ts +10 -0
  9. package/dist/cjs/BaselinesStore.js +36 -0
  10. package/dist/cjs/BaselinesStore.js.map +1 -0
  11. package/dist/cjs/DocumentManager.d.ts +31 -28
  12. package/dist/cjs/DocumentManager.js +44 -44
  13. package/dist/cjs/Entity.d.ts +96 -0
  14. package/dist/cjs/Entity.js +345 -0
  15. package/dist/cjs/Entity.js.map +1 -0
  16. package/dist/cjs/EntityStore.d.ts +36 -0
  17. package/dist/cjs/EntityStore.js +172 -0
  18. package/dist/cjs/EntityStore.js.map +1 -0
  19. package/dist/cjs/FakeWeakRef.d.ts +11 -11
  20. package/dist/cjs/FakeWeakRef.js +18 -18
  21. package/dist/cjs/IDBService.d.ts +9 -9
  22. package/dist/cjs/IDBService.js +63 -63
  23. package/dist/cjs/LocalHistoryStore.d.ts +15 -0
  24. package/dist/cjs/LocalHistoryStore.js +53 -0
  25. package/dist/cjs/LocalHistoryStore.js.map +1 -0
  26. package/dist/cjs/LocalReplicaStore.d.ts +13 -0
  27. package/dist/cjs/LocalReplicaStore.js +49 -0
  28. package/dist/cjs/LocalReplicaStore.js.map +1 -0
  29. package/dist/cjs/MessageCreator.d.ts +19 -0
  30. package/dist/cjs/MessageCreator.js +104 -0
  31. package/dist/cjs/MessageCreator.js.map +1 -0
  32. package/dist/cjs/Metadata.d.ts +91 -0
  33. package/dist/cjs/Metadata.js +250 -0
  34. package/dist/cjs/Metadata.js.map +1 -0
  35. package/dist/cjs/OperationsStore.d.ts +38 -0
  36. package/dist/cjs/OperationsStore.js +146 -0
  37. package/dist/cjs/OperationsStore.js.map +1 -0
  38. package/dist/cjs/PresenceManager.d.ts +30 -0
  39. package/dist/cjs/PresenceManager.js +89 -0
  40. package/dist/cjs/PresenceManager.js.map +1 -0
  41. package/dist/cjs/Query.d.ts +26 -0
  42. package/dist/cjs/Query.js +86 -0
  43. package/dist/cjs/Query.js.map +1 -0
  44. package/dist/cjs/QueryMaker.d.ts +18 -0
  45. package/dist/cjs/QueryMaker.js +98 -0
  46. package/dist/cjs/QueryMaker.js.map +1 -0
  47. package/dist/cjs/QueryStore.d.ts +38 -0
  48. package/dist/cjs/QueryStore.js +146 -0
  49. package/dist/cjs/QueryStore.js.map +1 -0
  50. package/dist/cjs/SchemaStore.d.ts +9 -0
  51. package/dist/cjs/SchemaStore.js +35 -0
  52. package/dist/cjs/SchemaStore.js.map +1 -0
  53. package/dist/cjs/Storage.d.ts +147 -0
  54. package/dist/cjs/Storage.js +346 -0
  55. package/dist/cjs/Storage.js.map +1 -0
  56. package/dist/cjs/Sync.d.ts +117 -0
  57. package/dist/cjs/Sync.js +561 -0
  58. package/dist/cjs/Sync.js.map +1 -0
  59. package/dist/cjs/SyncHarness.d.ts +45 -0
  60. package/dist/cjs/SyncHarness.js +110 -0
  61. package/dist/cjs/SyncHarness.js.map +1 -0
  62. package/dist/cjs/UndoHistory.d.ts +16 -16
  63. package/dist/cjs/UndoHistory.js +50 -50
  64. package/dist/cjs/__tests__/batching.test.d.ts +1 -1
  65. package/dist/cjs/__tests__/batching.test.js +44 -44
  66. package/dist/cjs/__tests__/documents.test.d.ts +1 -1
  67. package/dist/cjs/__tests__/documents.test.js +415 -415
  68. package/dist/cjs/__tests__/fixtures/testStorage.d.ts +123 -122
  69. package/dist/cjs/__tests__/fixtures/testStorage.js +117 -115
  70. package/dist/cjs/__tests__/fixtures/testStorage.js.map +1 -1
  71. package/dist/cjs/__tests__/legacyOids.test.d.ts +1 -1
  72. package/dist/cjs/__tests__/legacyOids.test.js +309 -123
  73. package/dist/cjs/__tests__/legacyOids.test.js.map +1 -1
  74. package/dist/cjs/__tests__/mutations.test.d.ts +1 -1
  75. package/dist/cjs/__tests__/mutations.test.js +41 -41
  76. package/dist/cjs/__tests__/queries.test.d.ts +1 -1
  77. package/dist/cjs/__tests__/queries.test.js +318 -318
  78. package/dist/cjs/__tests__/setup/indexedDB.d.ts +1 -1
  79. package/dist/cjs/__tests__/setup/indexedDB.js +3 -3
  80. package/dist/cjs/__tests__/undo.test.d.ts +1 -1
  81. package/dist/cjs/__tests__/undo.test.js +86 -86
  82. package/dist/cjs/client/Client.d.ts +98 -99
  83. package/dist/cjs/client/Client.js +227 -227
  84. package/dist/cjs/client/ClientDescriptor.d.ts +76 -74
  85. package/dist/cjs/client/ClientDescriptor.js +197 -194
  86. package/dist/cjs/client/ClientDescriptor.js.map +1 -1
  87. package/dist/cjs/client/constants.d.ts +1 -0
  88. package/dist/cjs/client/constants.js +5 -0
  89. package/dist/cjs/client/constants.js.map +1 -0
  90. package/dist/cjs/constants.d.ts +1 -1
  91. package/dist/cjs/constants.js +4 -4
  92. package/dist/cjs/context.d.ts +29 -29
  93. package/dist/cjs/context.js +2 -2
  94. package/dist/cjs/entities/DocumentFamiliyCache.d.ts +90 -90
  95. package/dist/cjs/entities/DocumentFamiliyCache.js +282 -282
  96. package/dist/cjs/entities/Entity.d.ts +206 -203
  97. package/dist/cjs/entities/Entity.js +520 -520
  98. package/dist/cjs/entities/EntityStore.d.ts +85 -85
  99. package/dist/cjs/entities/EntityStore.js +479 -479
  100. package/dist/cjs/files/EntityFile.d.ts +31 -31
  101. package/dist/cjs/files/EntityFile.js +76 -76
  102. package/dist/cjs/files/FileManager.d.ts +42 -42
  103. package/dist/cjs/files/FileManager.js +152 -152
  104. package/dist/cjs/files/FileStorage.d.ts +28 -28
  105. package/dist/cjs/files/FileStorage.js +104 -104
  106. package/dist/cjs/files/utils.d.ts +8 -8
  107. package/dist/cjs/files/utils.js +55 -55
  108. package/dist/cjs/files/utils.test.d.ts +1 -1
  109. package/dist/cjs/files/utils.test.js +80 -80
  110. package/dist/cjs/idb.d.ts +11 -11
  111. package/dist/cjs/idb.js +111 -111
  112. package/dist/cjs/index.d.ts +21 -21
  113. package/dist/cjs/index.js +23 -23
  114. package/dist/cjs/indexes.d.ts +3 -0
  115. package/dist/cjs/indexes.js +20 -0
  116. package/dist/cjs/indexes.js.map +1 -0
  117. package/dist/cjs/metadata/AckInfoStore.d.ts +10 -10
  118. package/dist/cjs/metadata/AckInfoStore.js +25 -25
  119. package/dist/cjs/metadata/BaselinesStore.d.ts +33 -33
  120. package/dist/cjs/metadata/BaselinesStore.js +89 -89
  121. package/dist/cjs/metadata/LocalHistoryStore.d.ts +15 -0
  122. package/dist/cjs/metadata/LocalHistoryStore.js +53 -0
  123. package/dist/cjs/metadata/LocalHistoryStore.js.map +1 -0
  124. package/dist/cjs/metadata/LocalReplicaStore.d.ts +17 -17
  125. package/dist/cjs/metadata/LocalReplicaStore.js +47 -47
  126. package/dist/cjs/metadata/MessageCreator.d.ts +19 -19
  127. package/dist/cjs/metadata/MessageCreator.js +127 -127
  128. package/dist/cjs/metadata/Metadata.d.ts +112 -112
  129. package/dist/cjs/metadata/Metadata.js +352 -352
  130. package/dist/cjs/metadata/OperationsStore.d.ts +53 -53
  131. package/dist/cjs/metadata/OperationsStore.js +152 -152
  132. package/dist/cjs/metadata/SchemaStore.d.ts +9 -9
  133. package/dist/cjs/metadata/SchemaStore.js +38 -38
  134. package/dist/cjs/metadata/openMetadataDatabase.d.ts +19 -17
  135. package/dist/cjs/metadata/openMetadataDatabase.js +219 -158
  136. package/dist/cjs/metadata/openMetadataDatabase.js.map +1 -1
  137. package/dist/cjs/migration/db.d.ts +8 -8
  138. package/dist/cjs/migration/db.js +111 -111
  139. package/dist/cjs/migration/errors.d.ts +5 -5
  140. package/dist/cjs/migration/errors.js +11 -11
  141. package/dist/cjs/migration/openDatabase.d.ts +20 -20
  142. package/dist/cjs/migration/openDatabase.js +428 -428
  143. package/dist/cjs/migration/paths.d.ts +6 -6
  144. package/dist/cjs/migration/paths.js +52 -52
  145. package/dist/cjs/migration/paths.test.d.ts +1 -1
  146. package/dist/cjs/migration/paths.test.js +90 -90
  147. package/dist/cjs/openDocumentDatabase.d.ts +12 -0
  148. package/dist/cjs/openDocumentDatabase.js +432 -0
  149. package/dist/cjs/openDocumentDatabase.js.map +1 -0
  150. package/dist/cjs/queries/BaseQuery.d.ts +53 -53
  151. package/dist/cjs/queries/BaseQuery.js +135 -135
  152. package/dist/cjs/queries/CollectionQueries.d.ts +55 -55
  153. package/dist/cjs/queries/CollectionQueries.js +91 -91
  154. package/dist/cjs/queries/FindAllQuery.d.ts +12 -12
  155. package/dist/cjs/queries/FindAllQuery.js +42 -42
  156. package/dist/cjs/queries/FindInfiniteQuery.d.ts +19 -19
  157. package/dist/cjs/queries/FindInfiniteQuery.js +69 -69
  158. package/dist/cjs/queries/FindOneQuery.d.ts +12 -12
  159. package/dist/cjs/queries/FindOneQuery.js +42 -42
  160. package/dist/cjs/queries/FindPageQuery.d.ts +24 -24
  161. package/dist/cjs/queries/FindPageQuery.js +76 -76
  162. package/dist/cjs/queries/GetQuery.d.ts +10 -10
  163. package/dist/cjs/queries/GetQuery.js +29 -29
  164. package/dist/cjs/queries/LiveQuery.d.ts +28 -0
  165. package/dist/cjs/queries/LiveQuery.js +96 -0
  166. package/dist/cjs/queries/LiveQuery.js.map +1 -0
  167. package/dist/cjs/queries/LiveQueryMaker.d.ts +15 -0
  168. package/dist/cjs/queries/LiveQueryMaker.js +42 -0
  169. package/dist/cjs/queries/LiveQueryMaker.js.map +1 -0
  170. package/dist/cjs/queries/LiveQueryStore.d.ts +33 -0
  171. package/dist/cjs/queries/LiveQueryStore.js +85 -0
  172. package/dist/cjs/queries/LiveQueryStore.js.map +1 -0
  173. package/dist/cjs/queries/Query.d.ts +18 -0
  174. package/dist/cjs/queries/Query.js +36 -0
  175. package/dist/cjs/queries/Query.js.map +1 -0
  176. package/dist/cjs/queries/QueryCache.d.ts +16 -16
  177. package/dist/cjs/queries/QueryCache.js +41 -41
  178. package/dist/cjs/queries/QueryMaker.d.ts +14 -0
  179. package/dist/cjs/queries/QueryMaker.js +42 -0
  180. package/dist/cjs/queries/QueryMaker.js.map +1 -0
  181. package/dist/cjs/queries/QueryStore.d.ts +35 -0
  182. package/dist/cjs/queries/QueryStore.js +130 -0
  183. package/dist/cjs/queries/QueryStore.js.map +1 -0
  184. package/dist/cjs/queries/dbQueries.d.ts +22 -22
  185. package/dist/cjs/queries/dbQueries.js +125 -125
  186. package/dist/cjs/queries/keys.d.ts +10 -10
  187. package/dist/cjs/queries/keys.js +33 -33
  188. package/dist/cjs/queries/ranges.d.ts +2 -2
  189. package/dist/cjs/queries/ranges.js +69 -69
  190. package/dist/cjs/queries/types.d.ts +6 -6
  191. package/dist/cjs/queries/types.js +2 -2
  192. package/dist/cjs/queries/utils.d.ts +3 -3
  193. package/dist/cjs/queries/utils.js +24 -24
  194. package/dist/cjs/queries2/BaseQuery.d.ts +39 -0
  195. package/dist/cjs/queries2/BaseQuery.js +99 -0
  196. package/dist/cjs/queries2/BaseQuery.js.map +1 -0
  197. package/dist/cjs/queries2/CollectionQueries.d.ts +55 -0
  198. package/dist/cjs/queries2/CollectionQueries.js +83 -0
  199. package/dist/cjs/queries2/CollectionQueries.js.map +1 -0
  200. package/dist/cjs/queries2/FindAllQuery.d.ts +11 -0
  201. package/dist/cjs/queries2/FindAllQuery.js +34 -0
  202. package/dist/cjs/queries2/FindAllQuery.js.map +1 -0
  203. package/dist/cjs/queries2/FindInfiniteQuery.d.ts +18 -0
  204. package/dist/cjs/queries2/FindInfiniteQuery.js +61 -0
  205. package/dist/cjs/queries2/FindInfiniteQuery.js.map +1 -0
  206. package/dist/cjs/queries2/FindOneQuery.d.ts +11 -0
  207. package/dist/cjs/queries2/FindOneQuery.js +34 -0
  208. package/dist/cjs/queries2/FindOneQuery.js.map +1 -0
  209. package/dist/cjs/queries2/FindPageQuery.d.ts +23 -0
  210. package/dist/cjs/queries2/FindPageQuery.js +68 -0
  211. package/dist/cjs/queries2/FindPageQuery.js.map +1 -0
  212. package/dist/cjs/queries2/GetQuery.d.ts +10 -0
  213. package/dist/cjs/queries2/GetQuery.js +30 -0
  214. package/dist/cjs/queries2/GetQuery.js.map +1 -0
  215. package/dist/cjs/queries2/QueryCache.d.ts +16 -0
  216. package/dist/cjs/queries2/QueryCache.js +40 -0
  217. package/dist/cjs/queries2/QueryCache.js.map +1 -0
  218. package/dist/cjs/queries2/dbQueries.d.ts +22 -0
  219. package/dist/cjs/queries2/dbQueries.js +126 -0
  220. package/dist/cjs/queries2/dbQueries.js.map +1 -0
  221. package/dist/cjs/queries2/keys.d.ts +10 -0
  222. package/dist/cjs/queries2/keys.js +34 -0
  223. package/dist/cjs/queries2/keys.js.map +1 -0
  224. package/dist/cjs/queries2/ranges.d.ts +2 -0
  225. package/dist/cjs/queries2/ranges.js +70 -0
  226. package/dist/cjs/queries2/ranges.js.map +1 -0
  227. package/dist/cjs/queries2/types.d.ts +6 -0
  228. package/dist/cjs/queries2/types.js +3 -0
  229. package/dist/cjs/queries2/types.js.map +1 -0
  230. package/dist/cjs/queries2/utils.d.ts +1 -0
  231. package/dist/cjs/queries2/utils.js +20 -0
  232. package/dist/cjs/queries2/utils.js.map +1 -0
  233. package/dist/cjs/reactives/DocumentFamiliyCache.d.ts +47 -0
  234. package/dist/cjs/reactives/DocumentFamiliyCache.js +211 -0
  235. package/dist/cjs/reactives/DocumentFamiliyCache.js.map +1 -0
  236. package/dist/cjs/reactives/Entity.d.ts +191 -0
  237. package/dist/cjs/reactives/Entity.js +463 -0
  238. package/dist/cjs/reactives/Entity.js.map +1 -0
  239. package/dist/cjs/reactives/EntityStore.d.ts +84 -0
  240. package/dist/cjs/reactives/EntityStore.js +422 -0
  241. package/dist/cjs/reactives/EntityStore.js.map +1 -0
  242. package/dist/cjs/reactives/FakeWeakRef.d.ts +11 -0
  243. package/dist/cjs/reactives/FakeWeakRef.js +19 -0
  244. package/dist/cjs/reactives/FakeWeakRef.js.map +1 -0
  245. package/dist/cjs/sync/FileSync.d.ts +23 -23
  246. package/dist/cjs/sync/FileSync.js +84 -84
  247. package/dist/cjs/sync/Heartbeat.d.ts +25 -25
  248. package/dist/cjs/sync/Heartbeat.js +63 -63
  249. package/dist/cjs/sync/PresenceManager.d.ts +43 -43
  250. package/dist/cjs/sync/PresenceManager.js +119 -119
  251. package/dist/cjs/sync/PushPullSync.d.ts +36 -36
  252. package/dist/cjs/sync/PushPullSync.js +143 -143
  253. package/dist/cjs/sync/ServerSyncEndpointProvider.d.ts +27 -27
  254. package/dist/cjs/sync/ServerSyncEndpointProvider.js +64 -64
  255. package/dist/cjs/sync/Sync.d.ts +146 -146
  256. package/dist/cjs/sync/Sync.js +270 -270
  257. package/dist/cjs/sync/Sync.js.map +1 -1
  258. package/dist/cjs/sync/WebSocketSync.d.ts +41 -41
  259. package/dist/cjs/sync/WebSocketSync.js +190 -190
  260. package/dist/cjs/types.d.ts +12 -12
  261. package/dist/cjs/types.js +2 -2
  262. package/dist/cjs/utils/Disposable.d.ts +6 -6
  263. package/dist/cjs/utils/Disposable.js +18 -18
  264. package/dist/cjs/utils/Resolvable.d.ts +8 -8
  265. package/dist/cjs/utils/Resolvable.js +22 -22
  266. package/dist/cjs/v2/AckInfoStore.d.ts +10 -0
  267. package/dist/cjs/v2/AckInfoStore.js +26 -0
  268. package/dist/cjs/v2/AckInfoStore.js.map +1 -0
  269. package/dist/cjs/v2/BaselinesStore.d.ts +10 -0
  270. package/dist/cjs/v2/BaselinesStore.js +36 -0
  271. package/dist/cjs/v2/BaselinesStore.js.map +1 -0
  272. package/dist/cjs/v2/DocumentManager.d.ts +19 -0
  273. package/dist/cjs/v2/DocumentManager.js +47 -0
  274. package/dist/cjs/v2/DocumentManager.js.map +1 -0
  275. package/dist/cjs/v2/Entity.d.ts +87 -0
  276. package/dist/cjs/v2/Entity.js +305 -0
  277. package/dist/cjs/v2/Entity.js.map +1 -0
  278. package/dist/cjs/v2/EntityStore.d.ts +37 -0
  279. package/dist/cjs/v2/EntityStore.js +165 -0
  280. package/dist/cjs/v2/EntityStore.js.map +1 -0
  281. package/dist/cjs/v2/IDBService.d.ts +7 -0
  282. package/dist/cjs/v2/IDBService.js +26 -0
  283. package/dist/cjs/v2/IDBService.js.map +1 -0
  284. package/dist/cjs/v2/LocalHistoryStore.d.ts +15 -0
  285. package/dist/cjs/v2/LocalHistoryStore.js +53 -0
  286. package/dist/cjs/v2/LocalHistoryStore.js.map +1 -0
  287. package/dist/cjs/v2/LocalReplicaStore.d.ts +14 -0
  288. package/dist/cjs/v2/LocalReplicaStore.js +49 -0
  289. package/dist/cjs/v2/LocalReplicaStore.js.map +1 -0
  290. package/dist/cjs/v2/MessageCreator.d.ts +19 -0
  291. package/dist/cjs/v2/MessageCreator.js +99 -0
  292. package/dist/cjs/v2/MessageCreator.js.map +1 -0
  293. package/dist/cjs/v2/Metadata.d.ts +90 -0
  294. package/dist/cjs/v2/Metadata.js +251 -0
  295. package/dist/cjs/v2/Metadata.js.map +1 -0
  296. package/dist/cjs/v2/OperationsStore.d.ts +38 -0
  297. package/dist/cjs/v2/OperationsStore.js +146 -0
  298. package/dist/cjs/v2/OperationsStore.js.map +1 -0
  299. package/dist/cjs/v2/PresenceManager.d.ts +24 -0
  300. package/dist/cjs/v2/PresenceManager.js +73 -0
  301. package/dist/cjs/v2/PresenceManager.js.map +1 -0
  302. package/dist/cjs/v2/Query.d.ts +24 -0
  303. package/dist/cjs/v2/Query.js +79 -0
  304. package/dist/cjs/v2/Query.js.map +1 -0
  305. package/dist/cjs/v2/QueryMaker.d.ts +16 -0
  306. package/dist/cjs/v2/QueryMaker.js +84 -0
  307. package/dist/cjs/v2/QueryMaker.js.map +1 -0
  308. package/dist/cjs/v2/QueryStore.d.ts +26 -0
  309. package/dist/cjs/v2/QueryStore.js +136 -0
  310. package/dist/cjs/v2/QueryStore.js.map +1 -0
  311. package/dist/cjs/v2/SchemaStore.d.ts +9 -0
  312. package/dist/cjs/v2/SchemaStore.js +35 -0
  313. package/dist/cjs/v2/SchemaStore.js.map +1 -0
  314. package/dist/cjs/v2/Storage.d.ts +80 -0
  315. package/dist/cjs/v2/Storage.js +154 -0
  316. package/dist/cjs/v2/Storage.js.map +1 -0
  317. package/dist/cjs/v2/Sync.d.ts +42 -0
  318. package/dist/cjs/v2/Sync.js +98 -0
  319. package/dist/cjs/v2/Sync.js.map +1 -0
  320. package/dist/cjs/v2/SyncHarness.d.ts +45 -0
  321. package/dist/cjs/v2/SyncHarness.js +110 -0
  322. package/dist/cjs/v2/SyncHarness.js.map +1 -0
  323. package/dist/cjs/v2/__tests__/documents.test.d.ts +1 -0
  324. package/dist/cjs/v2/__tests__/documents.test.js +185 -0
  325. package/dist/cjs/v2/__tests__/documents.test.js.map +1 -0
  326. package/dist/cjs/v2/__tests__/fixtures/testStorage.d.ts +189 -0
  327. package/dist/cjs/v2/__tests__/fixtures/testStorage.js +93 -0
  328. package/dist/cjs/v2/__tests__/fixtures/testStorage.js.map +1 -0
  329. package/dist/cjs/v2/__tests__/queries.test.d.ts +1 -0
  330. package/dist/cjs/v2/__tests__/queries.test.js +92 -0
  331. package/dist/cjs/v2/__tests__/queries.test.js.map +1 -0
  332. package/dist/cjs/v2/__tests__/setup/indexedDB.d.ts +1 -0
  333. package/dist/cjs/v2/__tests__/setup/indexedDB.js +4 -0
  334. package/dist/cjs/v2/__tests__/setup/indexedDB.js.map +1 -0
  335. package/dist/cjs/v2/constants.d.ts +1 -0
  336. package/dist/cjs/v2/constants.js +5 -0
  337. package/dist/cjs/v2/constants.js.map +1 -0
  338. package/dist/cjs/v2/idb.d.ts +6 -0
  339. package/dist/cjs/v2/idb.js +71 -0
  340. package/dist/cjs/v2/idb.js.map +1 -0
  341. package/dist/cjs/v2/index.d.ts +6 -0
  342. package/dist/cjs/v2/index.js +14 -0
  343. package/dist/cjs/v2/index.js.map +1 -0
  344. package/dist/cjs/v2/indexes.d.ts +3 -0
  345. package/dist/cjs/v2/indexes.js +20 -0
  346. package/dist/cjs/v2/indexes.js.map +1 -0
  347. package/dist/cjs/v2/openDocumentDatabase.d.ts +9 -0
  348. package/dist/cjs/v2/openDocumentDatabase.js +100 -0
  349. package/dist/cjs/v2/openDocumentDatabase.js.map +1 -0
  350. package/dist/cjs/v2/types.d.ts +3 -0
  351. package/dist/cjs/v2/types.js +3 -0
  352. package/dist/cjs/v2/types.js.map +1 -0
  353. package/dist/cjs/vanilla.d.ts +1 -1
  354. package/dist/cjs/vanilla.js +27 -27
  355. package/dist/esm/AckInfoStore.d.ts +10 -0
  356. package/dist/esm/AckInfoStore.js +22 -0
  357. package/dist/esm/AckInfoStore.js.map +1 -0
  358. package/dist/esm/BackoffScheduler.d.ts +19 -19
  359. package/dist/esm/BackoffScheduler.js +39 -39
  360. package/dist/esm/BaselinesStore.d.ts +10 -0
  361. package/dist/esm/BaselinesStore.js +32 -0
  362. package/dist/esm/BaselinesStore.js.map +1 -0
  363. package/dist/esm/DocumentManager.d.ts +28 -28
  364. package/dist/esm/DocumentManager.js +40 -40
  365. package/dist/esm/Entity.d.ts +96 -0
  366. package/dist/esm/Entity.js +337 -0
  367. package/dist/esm/Entity.js.map +1 -0
  368. package/dist/esm/EntityStore.d.ts +36 -0
  369. package/dist/esm/EntityStore.js +168 -0
  370. package/dist/esm/EntityStore.js.map +1 -0
  371. package/dist/esm/FakeWeakRef.d.ts +11 -11
  372. package/dist/esm/FakeWeakRef.js +14 -14
  373. package/dist/esm/IDBService.d.ts +9 -9
  374. package/dist/esm/IDBService.js +59 -59
  375. package/dist/esm/LocalHistoryStore.d.ts +15 -0
  376. package/dist/esm/LocalHistoryStore.js +49 -0
  377. package/dist/esm/LocalHistoryStore.js.map +1 -0
  378. package/dist/esm/LocalReplicaStore.d.ts +13 -0
  379. package/dist/esm/LocalReplicaStore.js +42 -0
  380. package/dist/esm/LocalReplicaStore.js.map +1 -0
  381. package/dist/esm/MessageCreator.d.ts +19 -0
  382. package/dist/esm/MessageCreator.js +97 -0
  383. package/dist/esm/MessageCreator.js.map +1 -0
  384. package/dist/esm/Metadata.d.ts +91 -0
  385. package/dist/esm/Metadata.js +245 -0
  386. package/dist/esm/Metadata.js.map +1 -0
  387. package/dist/esm/OperationsStore.d.ts +38 -0
  388. package/dist/esm/OperationsStore.js +142 -0
  389. package/dist/esm/OperationsStore.js.map +1 -0
  390. package/dist/esm/PresenceManager.d.ts +30 -0
  391. package/dist/esm/PresenceManager.js +85 -0
  392. package/dist/esm/PresenceManager.js.map +1 -0
  393. package/dist/esm/Query.d.ts +26 -0
  394. package/dist/esm/Query.js +82 -0
  395. package/dist/esm/Query.js.map +1 -0
  396. package/dist/esm/QueryMaker.d.ts +18 -0
  397. package/dist/esm/QueryMaker.js +94 -0
  398. package/dist/esm/QueryMaker.js.map +1 -0
  399. package/dist/esm/QueryStore.d.ts +38 -0
  400. package/dist/esm/QueryStore.js +142 -0
  401. package/dist/esm/QueryStore.js.map +1 -0
  402. package/dist/esm/SchemaStore.d.ts +9 -0
  403. package/dist/esm/SchemaStore.js +31 -0
  404. package/dist/esm/SchemaStore.js.map +1 -0
  405. package/dist/esm/Storage.d.ts +147 -0
  406. package/dist/esm/Storage.js +341 -0
  407. package/dist/esm/Storage.js.map +1 -0
  408. package/dist/esm/Sync.d.ts +117 -0
  409. package/dist/esm/Sync.js +553 -0
  410. package/dist/esm/Sync.js.map +1 -0
  411. package/dist/esm/SyncHarness.d.ts +45 -0
  412. package/dist/esm/SyncHarness.js +105 -0
  413. package/dist/esm/SyncHarness.js.map +1 -0
  414. package/dist/esm/UndoHistory.d.ts +16 -16
  415. package/dist/esm/UndoHistory.js +46 -46
  416. package/dist/esm/__tests__/batching.test.d.ts +1 -1
  417. package/dist/esm/__tests__/batching.test.js +42 -42
  418. package/dist/esm/__tests__/documents.test.d.ts +1 -1
  419. package/dist/esm/__tests__/documents.test.js +413 -413
  420. package/dist/esm/__tests__/fixtures/testStorage.d.ts +123 -122
  421. package/dist/esm/__tests__/fixtures/testStorage.js +113 -111
  422. package/dist/esm/__tests__/fixtures/testStorage.js.map +1 -1
  423. package/dist/esm/__tests__/legacyOids.test.d.ts +1 -1
  424. package/dist/esm/__tests__/legacyOids.test.js +307 -121
  425. package/dist/esm/__tests__/legacyOids.test.js.map +1 -1
  426. package/dist/esm/__tests__/mutations.test.d.ts +1 -1
  427. package/dist/esm/__tests__/mutations.test.js +39 -39
  428. package/dist/esm/__tests__/queries.test.d.ts +1 -1
  429. package/dist/esm/__tests__/queries.test.js +316 -316
  430. package/dist/esm/__tests__/setup/indexedDB.d.ts +1 -1
  431. package/dist/esm/__tests__/setup/indexedDB.js +1 -1
  432. package/dist/esm/__tests__/undo.test.d.ts +1 -1
  433. package/dist/esm/__tests__/undo.test.js +84 -84
  434. package/dist/esm/client/Client.d.ts +99 -99
  435. package/dist/esm/client/Client.js +223 -223
  436. package/dist/esm/client/ClientDescriptor.d.ts +76 -74
  437. package/dist/esm/client/ClientDescriptor.js +193 -190
  438. package/dist/esm/client/ClientDescriptor.js.map +1 -1
  439. package/dist/esm/client/constants.d.ts +1 -0
  440. package/dist/esm/client/constants.js +2 -0
  441. package/dist/esm/client/constants.js.map +1 -0
  442. package/dist/esm/constants.d.ts +1 -1
  443. package/dist/esm/constants.js +1 -1
  444. package/dist/esm/context.d.ts +29 -29
  445. package/dist/esm/context.js +1 -1
  446. package/dist/esm/entities/DocumentFamiliyCache.d.ts +90 -90
  447. package/dist/esm/entities/DocumentFamiliyCache.js +278 -278
  448. package/dist/esm/entities/Entity.d.ts +206 -203
  449. package/dist/esm/entities/Entity.js +515 -515
  450. package/dist/esm/entities/EntityStore.d.ts +85 -85
  451. package/dist/esm/entities/EntityStore.js +475 -475
  452. package/dist/esm/files/EntityFile.d.ts +31 -31
  453. package/dist/esm/files/EntityFile.js +72 -72
  454. package/dist/esm/files/FileManager.d.ts +42 -42
  455. package/dist/esm/files/FileManager.js +148 -148
  456. package/dist/esm/files/FileStorage.d.ts +28 -28
  457. package/dist/esm/files/FileStorage.js +99 -99
  458. package/dist/esm/files/utils.d.ts +8 -8
  459. package/dist/esm/files/utils.js +46 -46
  460. package/dist/esm/files/utils.test.d.ts +1 -1
  461. package/dist/esm/files/utils.test.js +78 -78
  462. package/dist/esm/idb.d.ts +11 -11
  463. package/dist/esm/idb.js +100 -100
  464. package/dist/esm/index.d.ts +21 -21
  465. package/dist/esm/index.js +12 -12
  466. package/dist/esm/indexes.d.ts +3 -0
  467. package/dist/esm/indexes.js +15 -0
  468. package/dist/esm/indexes.js.map +1 -0
  469. package/dist/esm/metadata/AckInfoStore.d.ts +10 -10
  470. package/dist/esm/metadata/AckInfoStore.js +21 -21
  471. package/dist/esm/metadata/BaselinesStore.d.ts +33 -33
  472. package/dist/esm/metadata/BaselinesStore.js +85 -85
  473. package/dist/esm/metadata/LocalHistoryStore.d.ts +15 -0
  474. package/dist/esm/metadata/LocalHistoryStore.js +49 -0
  475. package/dist/esm/metadata/LocalHistoryStore.js.map +1 -0
  476. package/dist/esm/metadata/LocalReplicaStore.d.ts +17 -17
  477. package/dist/esm/metadata/LocalReplicaStore.js +40 -40
  478. package/dist/esm/metadata/MessageCreator.d.ts +19 -19
  479. package/dist/esm/metadata/MessageCreator.js +123 -123
  480. package/dist/esm/metadata/Metadata.d.ts +112 -112
  481. package/dist/esm/metadata/Metadata.js +348 -348
  482. package/dist/esm/metadata/OperationsStore.d.ts +53 -53
  483. package/dist/esm/metadata/OperationsStore.js +148 -148
  484. package/dist/esm/metadata/SchemaStore.d.ts +9 -9
  485. package/dist/esm/metadata/SchemaStore.js +34 -34
  486. package/dist/esm/metadata/openMetadataDatabase.d.ts +19 -17
  487. package/dist/esm/metadata/openMetadataDatabase.js +214 -153
  488. package/dist/esm/metadata/openMetadataDatabase.js.map +1 -1
  489. package/dist/esm/migration/db.d.ts +8 -8
  490. package/dist/esm/migration/db.js +103 -103
  491. package/dist/esm/migration/errors.d.ts +5 -5
  492. package/dist/esm/migration/errors.js +7 -7
  493. package/dist/esm/migration/openDatabase.d.ts +20 -20
  494. package/dist/esm/migration/openDatabase.js +423 -423
  495. package/dist/esm/migration/paths.d.ts +6 -6
  496. package/dist/esm/migration/paths.js +48 -48
  497. package/dist/esm/migration/paths.test.d.ts +1 -1
  498. package/dist/esm/migration/paths.test.js +88 -88
  499. package/dist/esm/openDocumentDatabase.d.ts +12 -0
  500. package/dist/esm/openDocumentDatabase.js +428 -0
  501. package/dist/esm/openDocumentDatabase.js.map +1 -0
  502. package/dist/esm/queries/BaseQuery.d.ts +53 -53
  503. package/dist/esm/queries/BaseQuery.js +131 -131
  504. package/dist/esm/queries/CollectionQueries.d.ts +55 -55
  505. package/dist/esm/queries/CollectionQueries.js +87 -87
  506. package/dist/esm/queries/FindAllQuery.d.ts +12 -12
  507. package/dist/esm/queries/FindAllQuery.js +38 -38
  508. package/dist/esm/queries/FindInfiniteQuery.d.ts +19 -19
  509. package/dist/esm/queries/FindInfiniteQuery.js +65 -65
  510. package/dist/esm/queries/FindOneQuery.d.ts +12 -12
  511. package/dist/esm/queries/FindOneQuery.js +38 -38
  512. package/dist/esm/queries/FindPageQuery.d.ts +24 -24
  513. package/dist/esm/queries/FindPageQuery.js +72 -72
  514. package/dist/esm/queries/GetQuery.d.ts +10 -10
  515. package/dist/esm/queries/GetQuery.js +25 -25
  516. package/dist/esm/queries/LiveQuery.d.ts +28 -0
  517. package/dist/esm/queries/LiveQuery.js +92 -0
  518. package/dist/esm/queries/LiveQuery.js.map +1 -0
  519. package/dist/esm/queries/LiveQueryMaker.d.ts +15 -0
  520. package/dist/esm/queries/LiveQueryMaker.js +38 -0
  521. package/dist/esm/queries/LiveQueryMaker.js.map +1 -0
  522. package/dist/esm/queries/LiveQueryStore.d.ts +33 -0
  523. package/dist/esm/queries/LiveQueryStore.js +81 -0
  524. package/dist/esm/queries/LiveQueryStore.js.map +1 -0
  525. package/dist/esm/queries/Query.d.ts +18 -0
  526. package/dist/esm/queries/Query.js +32 -0
  527. package/dist/esm/queries/Query.js.map +1 -0
  528. package/dist/esm/queries/QueryCache.d.ts +16 -16
  529. package/dist/esm/queries/QueryCache.js +37 -37
  530. package/dist/esm/queries/QueryMaker.d.ts +14 -0
  531. package/dist/esm/queries/QueryMaker.js +38 -0
  532. package/dist/esm/queries/QueryMaker.js.map +1 -0
  533. package/dist/esm/queries/QueryStore.d.ts +35 -0
  534. package/dist/esm/queries/QueryStore.js +126 -0
  535. package/dist/esm/queries/QueryStore.js.map +1 -0
  536. package/dist/esm/queries/dbQueries.d.ts +22 -22
  537. package/dist/esm/queries/dbQueries.js +119 -119
  538. package/dist/esm/queries/keys.d.ts +10 -10
  539. package/dist/esm/queries/keys.js +29 -29
  540. package/dist/esm/queries/ranges.d.ts +2 -2
  541. package/dist/esm/queries/ranges.js +65 -65
  542. package/dist/esm/queries/types.d.ts +6 -6
  543. package/dist/esm/queries/types.js +1 -1
  544. package/dist/esm/queries/utils.d.ts +3 -3
  545. package/dist/esm/queries/utils.js +19 -19
  546. package/dist/esm/queries2/BaseQuery.d.ts +39 -0
  547. package/dist/esm/queries2/BaseQuery.js +95 -0
  548. package/dist/esm/queries2/BaseQuery.js.map +1 -0
  549. package/dist/esm/queries2/CollectionQueries.d.ts +55 -0
  550. package/dist/esm/queries2/CollectionQueries.js +79 -0
  551. package/dist/esm/queries2/CollectionQueries.js.map +1 -0
  552. package/dist/esm/queries2/FindAllQuery.d.ts +11 -0
  553. package/dist/esm/queries2/FindAllQuery.js +30 -0
  554. package/dist/esm/queries2/FindAllQuery.js.map +1 -0
  555. package/dist/esm/queries2/FindInfiniteQuery.d.ts +18 -0
  556. package/dist/esm/queries2/FindInfiniteQuery.js +57 -0
  557. package/dist/esm/queries2/FindInfiniteQuery.js.map +1 -0
  558. package/dist/esm/queries2/FindOneQuery.d.ts +11 -0
  559. package/dist/esm/queries2/FindOneQuery.js +30 -0
  560. package/dist/esm/queries2/FindOneQuery.js.map +1 -0
  561. package/dist/esm/queries2/FindPageQuery.d.ts +23 -0
  562. package/dist/esm/queries2/FindPageQuery.js +64 -0
  563. package/dist/esm/queries2/FindPageQuery.js.map +1 -0
  564. package/dist/esm/queries2/GetQuery.d.ts +10 -0
  565. package/dist/esm/queries2/GetQuery.js +26 -0
  566. package/dist/esm/queries2/GetQuery.js.map +1 -0
  567. package/dist/esm/queries2/QueryCache.d.ts +16 -0
  568. package/dist/esm/queries2/QueryCache.js +36 -0
  569. package/dist/esm/queries2/QueryCache.js.map +1 -0
  570. package/dist/esm/queries2/dbQueries.d.ts +22 -0
  571. package/dist/esm/queries2/dbQueries.js +120 -0
  572. package/dist/esm/queries2/dbQueries.js.map +1 -0
  573. package/dist/esm/queries2/keys.d.ts +10 -0
  574. package/dist/esm/queries2/keys.js +30 -0
  575. package/dist/esm/queries2/keys.js.map +1 -0
  576. package/dist/esm/queries2/ranges.d.ts +2 -0
  577. package/dist/esm/queries2/ranges.js +66 -0
  578. package/dist/esm/queries2/ranges.js.map +1 -0
  579. package/dist/esm/queries2/types.d.ts +6 -0
  580. package/dist/esm/queries2/types.js +2 -0
  581. package/dist/esm/queries2/types.js.map +1 -0
  582. package/dist/esm/queries2/utils.d.ts +1 -0
  583. package/dist/esm/queries2/utils.js +16 -0
  584. package/dist/esm/queries2/utils.js.map +1 -0
  585. package/dist/esm/reactives/DocumentFamiliyCache.d.ts +47 -0
  586. package/dist/esm/reactives/DocumentFamiliyCache.js +207 -0
  587. package/dist/esm/reactives/DocumentFamiliyCache.js.map +1 -0
  588. package/dist/esm/reactives/Entity.d.ts +191 -0
  589. package/dist/esm/reactives/Entity.js +458 -0
  590. package/dist/esm/reactives/Entity.js.map +1 -0
  591. package/dist/esm/reactives/EntityStore.d.ts +84 -0
  592. package/dist/esm/reactives/EntityStore.js +418 -0
  593. package/dist/esm/reactives/EntityStore.js.map +1 -0
  594. package/dist/esm/reactives/FakeWeakRef.d.ts +11 -0
  595. package/dist/esm/reactives/FakeWeakRef.js +15 -0
  596. package/dist/esm/reactives/FakeWeakRef.js.map +1 -0
  597. package/dist/esm/sync/FileSync.d.ts +23 -23
  598. package/dist/esm/sync/FileSync.js +80 -80
  599. package/dist/esm/sync/Heartbeat.d.ts +25 -25
  600. package/dist/esm/sync/Heartbeat.js +59 -59
  601. package/dist/esm/sync/PresenceManager.d.ts +43 -43
  602. package/dist/esm/sync/PresenceManager.js +115 -115
  603. package/dist/esm/sync/PushPullSync.d.ts +36 -36
  604. package/dist/esm/sync/PushPullSync.js +139 -139
  605. package/dist/esm/sync/ServerSyncEndpointProvider.d.ts +27 -27
  606. package/dist/esm/sync/ServerSyncEndpointProvider.js +57 -57
  607. package/dist/esm/sync/Sync.d.ts +146 -146
  608. package/dist/esm/sync/Sync.js +265 -265
  609. package/dist/esm/sync/Sync.js.map +1 -1
  610. package/dist/esm/sync/{WebSocketSync.d.ts → WebsocketSync.d.ts} +41 -41
  611. package/dist/esm/sync/{WebSocketSync.js → WebsocketSync.js} +186 -186
  612. package/dist/esm/types.d.ts +12 -12
  613. package/dist/esm/types.js +1 -1
  614. package/dist/esm/utils/Disposable.d.ts +6 -6
  615. package/dist/esm/utils/Disposable.js +14 -14
  616. package/dist/esm/utils/Resolvable.d.ts +8 -8
  617. package/dist/esm/utils/Resolvable.js +18 -18
  618. package/dist/esm/v2/AckInfoStore.d.ts +10 -0
  619. package/dist/esm/v2/AckInfoStore.js +22 -0
  620. package/dist/esm/v2/AckInfoStore.js.map +1 -0
  621. package/dist/esm/v2/BaselinesStore.d.ts +10 -0
  622. package/dist/esm/v2/BaselinesStore.js +32 -0
  623. package/dist/esm/v2/BaselinesStore.js.map +1 -0
  624. package/dist/esm/v2/DocumentManager.d.ts +19 -0
  625. package/dist/esm/v2/DocumentManager.js +43 -0
  626. package/dist/esm/v2/DocumentManager.js.map +1 -0
  627. package/dist/esm/v2/Entity.d.ts +91 -0
  628. package/dist/esm/v2/Entity.js +305 -0
  629. package/dist/esm/v2/Entity.js.map +1 -0
  630. package/dist/esm/v2/EntityStore.d.ts +37 -0
  631. package/dist/esm/v2/EntityStore.js +166 -0
  632. package/dist/esm/v2/EntityStore.js.map +1 -0
  633. package/dist/esm/v2/IDBService.d.ts +7 -0
  634. package/dist/esm/v2/IDBService.js +22 -0
  635. package/dist/esm/v2/IDBService.js.map +1 -0
  636. package/dist/esm/v2/LocalHistoryStore.d.ts +15 -0
  637. package/dist/esm/v2/LocalHistoryStore.js +49 -0
  638. package/dist/esm/v2/LocalHistoryStore.js.map +1 -0
  639. package/dist/esm/v2/LocalReplicaStore.d.ts +14 -0
  640. package/dist/esm/v2/LocalReplicaStore.js +42 -0
  641. package/dist/esm/v2/LocalReplicaStore.js.map +1 -0
  642. package/dist/esm/v2/MessageCreator.d.ts +19 -0
  643. package/dist/esm/v2/MessageCreator.js +92 -0
  644. package/dist/esm/v2/MessageCreator.js.map +1 -0
  645. package/dist/esm/v2/Metadata.d.ts +90 -0
  646. package/dist/esm/v2/Metadata.js +246 -0
  647. package/dist/esm/v2/Metadata.js.map +1 -0
  648. package/dist/esm/v2/OperationsStore.d.ts +38 -0
  649. package/dist/esm/v2/OperationsStore.js +142 -0
  650. package/dist/esm/v2/OperationsStore.js.map +1 -0
  651. package/dist/esm/v2/PresenceManager.d.ts +24 -0
  652. package/dist/esm/v2/PresenceManager.js +69 -0
  653. package/dist/esm/v2/PresenceManager.js.map +1 -0
  654. package/dist/esm/v2/Query.d.ts +24 -0
  655. package/dist/esm/v2/Query.js +75 -0
  656. package/dist/esm/v2/Query.js.map +1 -0
  657. package/dist/esm/v2/QueryMaker.d.ts +16 -0
  658. package/dist/esm/v2/QueryMaker.js +80 -0
  659. package/dist/esm/v2/QueryMaker.js.map +1 -0
  660. package/dist/esm/v2/QueryStore.d.ts +26 -0
  661. package/dist/esm/v2/QueryStore.js +132 -0
  662. package/dist/esm/v2/QueryStore.js.map +1 -0
  663. package/dist/esm/v2/SchemaStore.d.ts +9 -0
  664. package/dist/esm/v2/SchemaStore.js +31 -0
  665. package/dist/esm/v2/SchemaStore.js.map +1 -0
  666. package/dist/esm/v2/Storage.d.ts +80 -0
  667. package/dist/esm/v2/Storage.js +149 -0
  668. package/dist/esm/v2/Storage.js.map +1 -0
  669. package/dist/esm/v2/Sync.d.ts +42 -0
  670. package/dist/esm/v2/Sync.js +94 -0
  671. package/dist/esm/v2/Sync.js.map +1 -0
  672. package/dist/esm/v2/SyncHarness.d.ts +45 -0
  673. package/dist/esm/v2/SyncHarness.js +105 -0
  674. package/dist/esm/v2/SyncHarness.js.map +1 -0
  675. package/dist/esm/v2/__tests__/documents.test.d.ts +1 -0
  676. package/dist/esm/v2/__tests__/documents.test.js +208 -0
  677. package/dist/esm/v2/__tests__/documents.test.js.map +1 -0
  678. package/dist/esm/v2/__tests__/fixtures/testStorage.d.ts +223 -0
  679. package/dist/esm/v2/__tests__/fixtures/testStorage.js +106 -0
  680. package/dist/esm/v2/__tests__/fixtures/testStorage.js.map +1 -0
  681. package/dist/esm/v2/__tests__/queries.test.d.ts +1 -0
  682. package/dist/esm/v2/__tests__/queries.test.js +90 -0
  683. package/dist/esm/v2/__tests__/queries.test.js.map +1 -0
  684. package/dist/esm/v2/__tests__/setup/indexedDB.d.ts +1 -0
  685. package/dist/esm/v2/__tests__/setup/indexedDB.js +2 -0
  686. package/dist/esm/v2/__tests__/setup/indexedDB.js.map +1 -0
  687. package/dist/esm/v2/constants.d.ts +1 -0
  688. package/dist/esm/v2/constants.js +2 -0
  689. package/dist/esm/v2/constants.js.map +1 -0
  690. package/dist/esm/v2/idb.d.ts +6 -0
  691. package/dist/esm/v2/idb.js +65 -0
  692. package/dist/esm/v2/idb.js.map +1 -0
  693. package/dist/esm/v2/index.d.ts +6 -0
  694. package/dist/esm/v2/index.js +5 -0
  695. package/dist/esm/v2/index.js.map +1 -0
  696. package/dist/esm/v2/indexes.d.ts +3 -0
  697. package/dist/esm/v2/indexes.js +15 -0
  698. package/dist/esm/v2/indexes.js.map +1 -0
  699. package/dist/esm/v2/openDocumentDatabase.d.ts +9 -0
  700. package/dist/esm/v2/openDocumentDatabase.js +96 -0
  701. package/dist/esm/v2/openDocumentDatabase.js.map +1 -0
  702. package/dist/esm/v2/types.d.ts +3 -0
  703. package/dist/esm/v2/types.js +2 -0
  704. package/dist/esm/v2/types.js.map +1 -0
  705. package/dist/esm/vanilla.d.ts +1 -1
  706. package/dist/esm/vanilla.js +2 -2
  707. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  708. package/dist/tsconfig.tsbuildinfo +1 -1
  709. package/package.json +2 -2
  710. package/src/__tests__/fixtures/testStorage.ts +8 -1
  711. package/src/__tests__/legacyOids.test.ts +240 -49
  712. package/src/client/ClientDescriptor.ts +6 -0
  713. package/src/client/constants.ts +1 -0
  714. package/src/entities/Entity.ts +10 -2
  715. package/src/metadata/openMetadataDatabase.ts +65 -2
  716. package/src/sync/Sync.ts +1 -0
  717. /package/dist/esm/sync/{WebSocketSync.js.map → WebsocketSync.js.map} +0 -0
@@ -1,480 +1,480 @@
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 { schema: null, readonlyKeys: [] };
35
- }
36
- const schema = this.schema.collections[collection];
37
- return {
38
- readonlyKeys: [schema.primaryKey],
39
- schema: {
40
- type: 'object',
41
- properties: schema.fields,
42
- },
43
- };
44
- };
45
- this.refreshFamilyCache = async (familyCache, dropUnconfirmed = false, dropAll = false) => {
46
- // avoid writing to disposed db
47
- if (this._disposed) {
48
- this.context.log('debug', `EntityStore is disposed, not refreshing ${familyCache.oid} cache`);
49
- return;
50
- }
51
- // metadata must be loaded from database to initialize family cache
52
- const transaction = this.meta.createTransaction([
53
- 'baselines',
54
- 'operations',
55
- ]);
56
- const baselines = [];
57
- const operations = [];
58
- await Promise.all([
59
- this.meta.baselines.iterateOverAllForDocument(familyCache.oid, (baseline) => {
60
- baselines.push(baseline);
61
- }, {
62
- transaction,
63
- mode: 'readwrite',
64
- }),
65
- this.meta.operations.iterateOverAllOperationsForDocument(familyCache.oid, (op) => {
66
- op.confirmed = true;
67
- operations.push(op);
68
- }, { transaction, mode: 'readwrite' }),
69
- ]);
70
- familyCache.reset({
71
- operations,
72
- baselines,
73
- dropExistingUnconfirmed: dropUnconfirmed,
74
- dropAll,
75
- });
76
- };
77
- this.openFamilyCache = async (oid) => {
78
- const documentOid = (0, common_1.getOidRoot)(oid);
79
- let familyCache = this.documentFamilyCaches.get(documentOid);
80
- if (!familyCache) {
81
- this.context.log('debug', 'opening family cache for', documentOid);
82
- // metadata must be loaded from database to initialize family cache
83
- familyCache = new DocumentFamiliyCache_js_1.DocumentFamilyCache({
84
- oid: documentOid,
85
- store: this,
86
- context: this.context,
87
- });
88
- // PROBLEM: because the next line is async, it yields to
89
- // queued promises which may need data from this cache,
90
- // but the cache is empty. But if we move the set to
91
- // after the async, we can clobber an existing cache
92
- // with race conditions...
93
- // So as an attempt to fix that, I've added a promise
94
- // on DocumentFamilyCache which I manually resolve
95
- // with setInitialized, then await initializedPromise
96
- // further down even if there was a cache hit.
97
- // Surely there is a better pattern for this.
98
- // FIXME:
99
- this.documentFamilyCaches.set(documentOid, familyCache);
100
- await this.refreshFamilyCache(familyCache);
101
- familyCache.setInitialized();
102
- // this.unsubscribes.push(
103
- // familyCache.subscribe('change:*', this.onEntityChange),
104
- // );
105
- // TODO: cleanup cache when all documents are disposed
106
- }
107
- await familyCache.initializedPromise;
108
- return familyCache;
109
- };
110
- this.onEntityChange = async (oid) => {
111
- // queueMicrotask(() => this.writeDocumentToStorage(oid));
112
- };
113
- this.writeDocumentToStorage = async (oid) => {
114
- if (this._disposed) {
115
- this.log('warn', 'EntityStore is disposed, not writing to storage');
116
- return;
117
- }
118
- const rootOid = (0, common_1.getOidRoot)(oid);
119
- const { id, collection } = (0, common_1.decomposeOid)(rootOid);
120
- const entity = await this.get(rootOid);
121
- if (this._disposed) {
122
- this.log('warn', 'EntityStore is disposed, not writing to storage');
123
- return;
124
- }
125
- const snapshot = entity === null || entity === void 0 ? void 0 : entity.getSnapshot();
126
- if (snapshot) {
127
- const stored = (0, common_1.getIndexValues)(this.schema.collections[collection], snapshot);
128
- try {
129
- const tx = this.db.transaction(collection, 'readwrite');
130
- const store = tx.objectStore(collection);
131
- await (0, idb_js_1.storeRequestPromise)(store.put(stored));
132
- this.log('info', '📝', 'wrote', collection, id, 'to storage', stored);
133
- }
134
- catch (err) {
135
- // if the document can't be written, something's very wrong :(
136
- // log the error and move on...
137
- 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));
138
- }
139
- }
140
- else {
141
- const tx = this.db.transaction(collection, 'readwrite');
142
- const store = tx.objectStore(collection);
143
- await (0, idb_js_1.storeRequestPromise)(store.delete(id));
144
- this.log('info', '❌', 'deleted', collection, id, 'from storage');
145
- }
146
- };
147
- this.get = async (oid) => {
148
- const familyCache = await this.openFamilyCache(oid);
149
- const { schema, readonlyKeys } = this.getDocumentSchema(oid);
150
- if (!schema) {
151
- return null;
152
- }
153
- return familyCache.getEntity(oid, schema, undefined, readonlyKeys);
154
- };
155
- /**
156
- * Advanced usage!
157
- * Immediately returns an entity if it exists in the memory cache. An
158
- * entity would be cached if it has been retrieved by a live query.
159
- */
160
- this.getCached = (oid) => {
161
- const cache = this.documentFamilyCaches.get(oid);
162
- if (cache) {
163
- const { schema, readonlyKeys } = this.getDocumentSchema(oid);
164
- if (!schema) {
165
- return null;
166
- }
167
- return cache.getEntity(oid, schema, undefined, readonlyKeys);
168
- }
169
- return null;
170
- };
171
- /**
172
- * Creates a new document and returns an Entity for it. The created
173
- * document is submitted to storage and sync.
174
- */
175
- this.create = async (initial, oid, options) => {
176
- // remove all OID associations from initial data
177
- (0, common_1.removeOidsFromAllSubObjects)(initial);
178
- // first grab any file and replace them with refs
179
- const processed = (0, utils_js_1.processValueFiles)(initial, this.files.add);
180
- (0, common_1.assignOid)(processed, oid);
181
- const operations = this.meta.patchCreator.createInitialize(processed, oid);
182
- const familyCache = await this.openFamilyCache(oid);
183
- familyCache.insertLocalOperations(operations);
184
- // don't enqueue these, submit as distinct operation.
185
- // we do this so it can be immediately queryable from storage...
186
- // only holding it in memory would introduce lag before it shows up
187
- // in other queries.
188
- await this.submitOperations(operations, options);
189
- const { schema, readonlyKeys } = this.getDocumentSchema(oid);
190
- if (!schema) {
191
- 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.`);
192
- }
193
- return familyCache.getEntity(oid, schema, undefined, readonlyKeys);
194
- };
195
- this.addOperationsToOpenCaches = async (operations, info) => {
196
- const operationsByOid = (0, common_1.groupPatchesByRootOid)(operations);
197
- const oids = Object.keys(operationsByOid);
198
- oids.forEach((oid) => {
199
- const familyCache = this.documentFamilyCaches.get(oid);
200
- if (familyCache) {
201
- this.log('adding', info.confirmed ? 'confirmed' : 'unconfirmed', 'operations to cache', oid, operationsByOid[oid].length);
202
- if (info.isLocal) {
203
- familyCache.insertLocalOperations(operationsByOid[oid]);
204
- }
205
- else {
206
- familyCache.insertOperations(operationsByOid[oid], info);
207
- }
208
- }
209
- });
210
- };
211
- this.addBaselinesToOpenCaches = async (baselines, info) => {
212
- const baselinesByOid = (0, common_1.groupBaselinesByRootOid)(baselines);
213
- const oids = Object.keys(baselinesByOid);
214
- oids.forEach((oid) => {
215
- const cache = this.documentFamilyCaches.get(oid);
216
- if (cache) {
217
- this.log('adding', 'baselines to cache', oid, baselinesByOid[oid].length);
218
- cache.insertBaselines(baselinesByOid[oid], info);
219
- }
220
- });
221
- };
222
- this.addDataToOpenCaches = ({ baselines, operations, reset, isLocal, }) => {
223
- var _a, _b, _c, _d;
224
- const baselinesByDocumentOid = (0, common_1.groupBaselinesByRootOid)(baselines);
225
- const operationsByDocumentOid = (0, common_1.groupPatchesByRootOid)(operations);
226
- const allDocumentOids = Array.from(new Set(Object.keys(baselinesByDocumentOid).concat(Object.keys(operationsByDocumentOid))));
227
- for (const oid of allDocumentOids) {
228
- const familyCache = this.documentFamilyCaches.get(oid);
229
- if (familyCache) {
230
- familyCache.addData({
231
- operations: operationsByDocumentOid[oid] || [],
232
- baselines: baselinesByDocumentOid[oid] || [],
233
- reset,
234
- isLocal,
235
- });
236
- this.log('debug', 'Added data to cache for', oid, (_b = (_a = operationsByDocumentOid[oid]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, 'operations', (_d = (_c = baselinesByDocumentOid[oid]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0, 'baselines');
237
- }
238
- else {
239
- this.log('debug', 'Could not add data to cache for', oid, 'because it is not open');
240
- }
241
- }
242
- return allDocumentOids;
243
- };
244
- this.addData = async ({ operations, baselines, reset, }) => {
245
- if (this._disposed) {
246
- this.log('warn', 'EntityStore is disposed, not adding data');
247
- return;
248
- }
249
- // convert operations to tagged operations with confirmed = false
250
- // while we process and store them. this is in-place so as to
251
- // not allocate a bunch of objects...
252
- const taggedOperations = operations;
253
- for (const op of taggedOperations) {
254
- op.confirmed = false;
255
- }
256
- let allDocumentOids = [];
257
- // in a reset scenario, it only makes things confusing if we
258
- // optimistically apply incoming operations, since the local
259
- // history is out of sync
260
- if (reset) {
261
- this.log('Resetting local store to replicate remote synced data', baselines.length, 'baselines, and', operations.length, 'operations');
262
- await this.meta.reset();
263
- await this.resetStoredDocuments();
264
- allDocumentOids = Array.from(new Set(baselines
265
- .map((b) => (0, common_1.getOidRoot)(b.oid))
266
- .concat(operations.map((o) => (0, common_1.getOidRoot)(o.oid)))));
267
- }
268
- else {
269
- // first, synchronously add data to any open caches for immediate change propagation
270
- allDocumentOids = this.addDataToOpenCaches({
271
- operations: taggedOperations,
272
- baselines,
273
- reset,
274
- });
275
- }
276
- // then, asynchronously add data to storage
277
- await this.meta.insertRemoteBaselines(baselines);
278
- await this.meta.insertRemoteOperations(operations);
279
- if (reset) {
280
- await this.refreshAllCaches(true, true);
281
- }
282
- // recompute all affected documents for querying
283
- for (const oid of allDocumentOids) {
284
- await this.writeDocumentToStorage(oid);
285
- }
286
- // notify active queries
287
- const affectedCollections = Array.from(new Set(allDocumentOids.map((oid) => (0, common_1.decomposeOid)(oid).collection)));
288
- this.context.log('changes to collections', affectedCollections);
289
- this.context.entityEvents.emit('collectionsChanged', affectedCollections);
290
- };
291
- this.addLocalOperations = async (operations) => {
292
- this.log('Adding local operations', operations.length);
293
- this.addOperationsToOpenCaches(operations, {
294
- isLocal: true,
295
- confirmed: false,
296
- });
297
- this.operationBatcher.add({
298
- key: this.currentBatchKey,
299
- items: operations,
300
- });
301
- };
302
- this.batch = ({ undoable = true, batchName = (0, common_1.generateId)(), max = null, timeout = this.defaultBatchTimeout, } = {}) => {
303
- const internalBatch = this.operationBatcher.add({
304
- key: batchName,
305
- max,
306
- timeout,
307
- items: [],
308
- userData: { undoable },
309
- });
310
- const externalApi = {
311
- run: (fn) => {
312
- // while the provided function runs, operations are forwarded
313
- // to the new batch instead of default. this relies on the function
314
- // being synchronous.
315
- this.currentBatchKey = batchName;
316
- fn();
317
- this.currentBatchKey = DEFAULT_BATCH_KEY;
318
- return externalApi;
319
- },
320
- flush: async () => {
321
- // before running a batch, the default operations must be flushed
322
- // this better preserves undo history behavior...
323
- // if we left the default batch open while flushing a named batch,
324
- // then the default batch would be flushed after the named batch,
325
- // and the default batch could contain operations both prior and
326
- // after the named batch. this would result in a confusing undo
327
- // history where the first undo might reverse changes before and
328
- // after a set of other changes.
329
- await this.operationBatcher.flush(DEFAULT_BATCH_KEY);
330
- return internalBatch.flush();
331
- },
332
- discard: () => {
333
- this.operationBatcher.discard(batchName);
334
- },
335
- };
336
- return externalApi;
337
- };
338
- /**
339
- * @deprecated use `batch` instead
340
- */
341
- this.flushPatches = async () => {
342
- await this.operationBatcher.flush(this.currentBatchKey);
343
- };
344
- this.flushAllBatches = async () => {
345
- await Promise.all(this.operationBatcher.flushAll());
346
- };
347
- this.flushOperations = async (operations, batchKey, meta) => {
348
- if (!operations.length)
349
- return;
350
- this.log('Flushing operations', operations.length, 'to storage / sync');
351
- // rewrite timestamps of all operations to now - this preserves
352
- // the linear history of operations which are sent to the server.
353
- // even if multiple batches are spun up in parallel and flushed
354
- // after delay, the final operations in each one should reflect
355
- // when the batch flushed, not when the changes were made.
356
- // This also corresponds to user-observed behavior, since unconfirmed
357
- // operations are applied universally after confirmed operations locally,
358
- // so even operations which were made before a remote operation but
359
- // have not been confirmed yet will appear to come after the remote one
360
- // despite the provisional timestamp being earlier (see DocumentFamilyCache#computeView)
361
- for (const op of operations) {
362
- op.timestamp = this.meta.now;
363
- }
364
- await this.submitOperations(operations, meta);
365
- };
366
- this.submitOperations = async (operations, { undoable = true } = {}) => {
367
- if (undoable) {
368
- // FIXME: this is too slow and needs to be optimized.
369
- this.undoHistory.addUndo(await this.createUndo(operations));
370
- }
371
- await this.meta.insertLocalOperation(operations);
372
- // confirm the operations
373
- this.addDataToOpenCaches({ operations, baselines: [] });
374
- // recompute all affected documents for querying
375
- const allDocumentOids = Array.from(new Set(operations.map((op) => (0, common_1.getOidRoot)(op.oid))));
376
- for (const oid of allDocumentOids) {
377
- await this.writeDocumentToStorage(oid);
378
- }
379
- // TODO: find a more efficient and straightforward way to update affected
380
- // queries. Move to Metadata?
381
- const affectedCollections = new Set(operations.map(({ oid }) => (0, common_1.decomposeOid)(oid).collection));
382
- this.context.log('changes to collections', affectedCollections);
383
- this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
384
- };
385
- this.getInverseOperations = async (ops) => {
386
- const grouped = (0, common_1.groupPatchesByIdentifier)(ops);
387
- const inverseOps = [];
388
- const getNow = () => this.meta.now;
389
- for (const [oid, patches] of Object.entries(grouped)) {
390
- const familyCache = await this.openFamilyCache(oid);
391
- let { view, deleted } = familyCache.computeConfirmedView(oid);
392
- const inverse = (0, common_1.getUndoOperations)(oid, view, patches, getNow);
393
- inverseOps.unshift(...inverse);
394
- }
395
- return inverseOps;
396
- };
397
- this.createUndo = async (ops) => {
398
- const inverseOps = await this.getInverseOperations(ops);
399
- return async () => {
400
- const redo = await this.createUndo(inverseOps);
401
- await this.submitOperations(inverseOps.map((op) => {
402
- op.timestamp = this.meta.now;
403
- return op;
404
- }),
405
- // undos should not generate their own undo operations
406
- // since they already calculate redo as the inverse.
407
- { undoable: false });
408
- return redo;
409
- };
410
- };
411
- this.delete = async (oid, options) => {
412
- (0, common_1.assert)(oid === (0, common_1.getOidRoot)(oid), 'Only root documents may be deleted via client methods');
413
- // we need to get all sub-object oids to delete alongside the root
414
- const allOids = await this.meta.getAllDocumentRelatedOids(oid);
415
- const patches = this.meta.patchCreator.createDeleteAll(allOids);
416
- // don't enqueue these, submit as distinct operation
417
- await this.submitOperations(patches, options);
418
- };
419
- this.deleteAll = async (oids, options) => {
420
- const allOids = await Promise.all(oids.map((oid) => this.meta.getAllDocumentRelatedOids(oid)));
421
- const patches = this.meta.patchCreator.createDeleteAll(allOids.flat());
422
- // don't enqueue these, submit as distinct operation
423
- await this.submitOperations(patches, options);
424
- };
425
- this.reset = async () => {
426
- this.context.log('warn', 'Resetting local database');
427
- await this.resetStoredDocuments();
428
- await this.refreshAllCaches(true);
429
- // this.context.entityEvents.emit(
430
- // 'collectionsChanged',
431
- // Object.keys(this.schema.collections),
432
- // );
433
- };
434
- this.destroy = async () => {
435
- this._disposed = true;
436
- for (const unsubscribe of this.unsubscribes) {
437
- unsubscribe();
438
- }
439
- for (const cache of this.documentFamilyCaches.values()) {
440
- cache.dispose();
441
- }
442
- this.documentFamilyCaches.clear();
443
- await this.flushAllBatches();
444
- };
445
- this.handleRebase = (baselines) => {
446
- this.log('debug', 'Reacting to rebases', baselines.length);
447
- // update any open caches with new baseline. this will automatically
448
- // drop operations before the baseline.
449
- this.addBaselinesToOpenCaches(baselines, { isLocal: true });
450
- };
451
- this.resetStoredDocuments = async () => {
452
- const tx = this.db.transaction(Object.keys(this.schema.collections), 'readwrite');
453
- for (const collection of Object.keys(this.schema.collections)) {
454
- const store = tx.objectStore(collection);
455
- await (0, idb_js_1.storeRequestPromise)(store.clear());
456
- }
457
- };
458
- this.refreshAllCaches = async (dropUnconfirmed = false, dropAll = false) => {
459
- for (const [_, cache] of this.documentFamilyCaches) {
460
- await this.refreshFamilyCache(cache, dropUnconfirmed, dropAll);
461
- }
462
- };
463
- this.context = context;
464
- this.defaultBatchTimeout = batchTimeout;
465
- this.meta = meta;
466
- this.files = files;
467
- this.operationBatcher = new common_1.Batcher(this.flushOperations);
468
- // initialize default batch
469
- this.operationBatcher.add({
470
- key: DEFAULT_BATCH_KEY,
471
- items: [],
472
- max: 100,
473
- timeout: batchTimeout,
474
- userData: { undoable: true },
475
- });
476
- this.unsubscribes.push(this.meta.subscribe('rebase', this.handleRebase));
477
- }
478
- }
479
- 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 { schema: null, readonlyKeys: [] };
35
+ }
36
+ const schema = this.schema.collections[collection];
37
+ return {
38
+ readonlyKeys: [schema.primaryKey],
39
+ schema: {
40
+ type: 'object',
41
+ properties: schema.fields,
42
+ },
43
+ };
44
+ };
45
+ this.refreshFamilyCache = async (familyCache, dropUnconfirmed = false, dropAll = false) => {
46
+ // avoid writing to disposed db
47
+ if (this._disposed) {
48
+ this.context.log('debug', `EntityStore is disposed, not refreshing ${familyCache.oid} cache`);
49
+ return;
50
+ }
51
+ // metadata must be loaded from database to initialize family cache
52
+ const transaction = this.meta.createTransaction([
53
+ 'baselines',
54
+ 'operations',
55
+ ]);
56
+ const baselines = [];
57
+ const operations = [];
58
+ await Promise.all([
59
+ this.meta.baselines.iterateOverAllForDocument(familyCache.oid, (baseline) => {
60
+ baselines.push(baseline);
61
+ }, {
62
+ transaction,
63
+ mode: 'readwrite',
64
+ }),
65
+ this.meta.operations.iterateOverAllOperationsForDocument(familyCache.oid, (op) => {
66
+ op.confirmed = true;
67
+ operations.push(op);
68
+ }, { transaction, mode: 'readwrite' }),
69
+ ]);
70
+ familyCache.reset({
71
+ operations,
72
+ baselines,
73
+ dropExistingUnconfirmed: dropUnconfirmed,
74
+ dropAll,
75
+ });
76
+ };
77
+ this.openFamilyCache = async (oid) => {
78
+ const documentOid = (0, common_1.getOidRoot)(oid);
79
+ let familyCache = this.documentFamilyCaches.get(documentOid);
80
+ if (!familyCache) {
81
+ this.context.log('debug', 'opening family cache for', documentOid);
82
+ // metadata must be loaded from database to initialize family cache
83
+ familyCache = new DocumentFamiliyCache_js_1.DocumentFamilyCache({
84
+ oid: documentOid,
85
+ store: this,
86
+ context: this.context,
87
+ });
88
+ // PROBLEM: because the next line is async, it yields to
89
+ // queued promises which may need data from this cache,
90
+ // but the cache is empty. But if we move the set to
91
+ // after the async, we can clobber an existing cache
92
+ // with race conditions...
93
+ // So as an attempt to fix that, I've added a promise
94
+ // on DocumentFamilyCache which I manually resolve
95
+ // with setInitialized, then await initializedPromise
96
+ // further down even if there was a cache hit.
97
+ // Surely there is a better pattern for this.
98
+ // FIXME:
99
+ this.documentFamilyCaches.set(documentOid, familyCache);
100
+ await this.refreshFamilyCache(familyCache);
101
+ familyCache.setInitialized();
102
+ // this.unsubscribes.push(
103
+ // familyCache.subscribe('change:*', this.onEntityChange),
104
+ // );
105
+ // TODO: cleanup cache when all documents are disposed
106
+ }
107
+ await familyCache.initializedPromise;
108
+ return familyCache;
109
+ };
110
+ this.onEntityChange = async (oid) => {
111
+ // queueMicrotask(() => this.writeDocumentToStorage(oid));
112
+ };
113
+ this.writeDocumentToStorage = async (oid) => {
114
+ if (this._disposed) {
115
+ this.log('warn', 'EntityStore is disposed, not writing to storage');
116
+ return;
117
+ }
118
+ const rootOid = (0, common_1.getOidRoot)(oid);
119
+ const { id, collection } = (0, common_1.decomposeOid)(rootOid);
120
+ const entity = await this.get(rootOid);
121
+ if (this._disposed) {
122
+ this.log('warn', 'EntityStore is disposed, not writing to storage');
123
+ return;
124
+ }
125
+ const snapshot = entity === null || entity === void 0 ? void 0 : entity.getSnapshot();
126
+ if (snapshot) {
127
+ const stored = (0, common_1.getIndexValues)(this.schema.collections[collection], snapshot);
128
+ try {
129
+ const tx = this.db.transaction(collection, 'readwrite');
130
+ const store = tx.objectStore(collection);
131
+ await (0, idb_js_1.storeRequestPromise)(store.put(stored));
132
+ this.log('info', '📝', 'wrote', collection, id, 'to storage', stored);
133
+ }
134
+ catch (err) {
135
+ // if the document can't be written, something's very wrong :(
136
+ // log the error and move on...
137
+ 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));
138
+ }
139
+ }
140
+ else {
141
+ const tx = this.db.transaction(collection, 'readwrite');
142
+ const store = tx.objectStore(collection);
143
+ await (0, idb_js_1.storeRequestPromise)(store.delete(id));
144
+ this.log('info', '❌', 'deleted', collection, id, 'from storage');
145
+ }
146
+ };
147
+ this.get = async (oid) => {
148
+ const familyCache = await this.openFamilyCache(oid);
149
+ const { schema, readonlyKeys } = this.getDocumentSchema(oid);
150
+ if (!schema) {
151
+ return null;
152
+ }
153
+ return familyCache.getEntity(oid, schema, undefined, readonlyKeys);
154
+ };
155
+ /**
156
+ * Advanced usage!
157
+ * Immediately returns an entity if it exists in the memory cache. An
158
+ * entity would be cached if it has been retrieved by a live query.
159
+ */
160
+ this.getCached = (oid) => {
161
+ const cache = this.documentFamilyCaches.get(oid);
162
+ if (cache) {
163
+ const { schema, readonlyKeys } = this.getDocumentSchema(oid);
164
+ if (!schema) {
165
+ return null;
166
+ }
167
+ return cache.getEntity(oid, schema, undefined, readonlyKeys);
168
+ }
169
+ return null;
170
+ };
171
+ /**
172
+ * Creates a new document and returns an Entity for it. The created
173
+ * document is submitted to storage and sync.
174
+ */
175
+ this.create = async (initial, oid, options) => {
176
+ // remove all OID associations from initial data
177
+ (0, common_1.removeOidsFromAllSubObjects)(initial);
178
+ // first grab any file and replace them with refs
179
+ const processed = (0, utils_js_1.processValueFiles)(initial, this.files.add);
180
+ (0, common_1.assignOid)(processed, oid);
181
+ const operations = this.meta.patchCreator.createInitialize(processed, oid);
182
+ const familyCache = await this.openFamilyCache(oid);
183
+ familyCache.insertLocalOperations(operations);
184
+ // don't enqueue these, submit as distinct operation.
185
+ // we do this so it can be immediately queryable from storage...
186
+ // only holding it in memory would introduce lag before it shows up
187
+ // in other queries.
188
+ await this.submitOperations(operations, options);
189
+ const { schema, readonlyKeys } = this.getDocumentSchema(oid);
190
+ if (!schema) {
191
+ 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.`);
192
+ }
193
+ return familyCache.getEntity(oid, schema, undefined, readonlyKeys);
194
+ };
195
+ this.addOperationsToOpenCaches = async (operations, info) => {
196
+ const operationsByOid = (0, common_1.groupPatchesByRootOid)(operations);
197
+ const oids = Object.keys(operationsByOid);
198
+ oids.forEach((oid) => {
199
+ const familyCache = this.documentFamilyCaches.get(oid);
200
+ if (familyCache) {
201
+ this.log('adding', info.confirmed ? 'confirmed' : 'unconfirmed', 'operations to cache', oid, operationsByOid[oid].length);
202
+ if (info.isLocal) {
203
+ familyCache.insertLocalOperations(operationsByOid[oid]);
204
+ }
205
+ else {
206
+ familyCache.insertOperations(operationsByOid[oid], info);
207
+ }
208
+ }
209
+ });
210
+ };
211
+ this.addBaselinesToOpenCaches = async (baselines, info) => {
212
+ const baselinesByOid = (0, common_1.groupBaselinesByRootOid)(baselines);
213
+ const oids = Object.keys(baselinesByOid);
214
+ oids.forEach((oid) => {
215
+ const cache = this.documentFamilyCaches.get(oid);
216
+ if (cache) {
217
+ this.log('adding', 'baselines to cache', oid, baselinesByOid[oid].length);
218
+ cache.insertBaselines(baselinesByOid[oid], info);
219
+ }
220
+ });
221
+ };
222
+ this.addDataToOpenCaches = ({ baselines, operations, reset, isLocal, }) => {
223
+ var _a, _b, _c, _d;
224
+ const baselinesByDocumentOid = (0, common_1.groupBaselinesByRootOid)(baselines);
225
+ const operationsByDocumentOid = (0, common_1.groupPatchesByRootOid)(operations);
226
+ const allDocumentOids = Array.from(new Set(Object.keys(baselinesByDocumentOid).concat(Object.keys(operationsByDocumentOid))));
227
+ for (const oid of allDocumentOids) {
228
+ const familyCache = this.documentFamilyCaches.get(oid);
229
+ if (familyCache) {
230
+ familyCache.addData({
231
+ operations: operationsByDocumentOid[oid] || [],
232
+ baselines: baselinesByDocumentOid[oid] || [],
233
+ reset,
234
+ isLocal,
235
+ });
236
+ this.log('debug', 'Added data to cache for', oid, (_b = (_a = operationsByDocumentOid[oid]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, 'operations', (_d = (_c = baselinesByDocumentOid[oid]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0, 'baselines');
237
+ }
238
+ else {
239
+ this.log('debug', 'Could not add data to cache for', oid, 'because it is not open');
240
+ }
241
+ }
242
+ return allDocumentOids;
243
+ };
244
+ this.addData = async ({ operations, baselines, reset, }) => {
245
+ if (this._disposed) {
246
+ this.log('warn', 'EntityStore is disposed, not adding data');
247
+ return;
248
+ }
249
+ // convert operations to tagged operations with confirmed = false
250
+ // while we process and store them. this is in-place so as to
251
+ // not allocate a bunch of objects...
252
+ const taggedOperations = operations;
253
+ for (const op of taggedOperations) {
254
+ op.confirmed = false;
255
+ }
256
+ let allDocumentOids = [];
257
+ // in a reset scenario, it only makes things confusing if we
258
+ // optimistically apply incoming operations, since the local
259
+ // history is out of sync
260
+ if (reset) {
261
+ this.log('Resetting local store to replicate remote synced data', baselines.length, 'baselines, and', operations.length, 'operations');
262
+ await this.meta.reset();
263
+ await this.resetStoredDocuments();
264
+ allDocumentOids = Array.from(new Set(baselines
265
+ .map((b) => (0, common_1.getOidRoot)(b.oid))
266
+ .concat(operations.map((o) => (0, common_1.getOidRoot)(o.oid)))));
267
+ }
268
+ else {
269
+ // first, synchronously add data to any open caches for immediate change propagation
270
+ allDocumentOids = this.addDataToOpenCaches({
271
+ operations: taggedOperations,
272
+ baselines,
273
+ reset,
274
+ });
275
+ }
276
+ // then, asynchronously add data to storage
277
+ await this.meta.insertRemoteBaselines(baselines);
278
+ await this.meta.insertRemoteOperations(operations);
279
+ if (reset) {
280
+ await this.refreshAllCaches(true, true);
281
+ }
282
+ // recompute all affected documents for querying
283
+ for (const oid of allDocumentOids) {
284
+ await this.writeDocumentToStorage(oid);
285
+ }
286
+ // notify active queries
287
+ const affectedCollections = Array.from(new Set(allDocumentOids.map((oid) => (0, common_1.decomposeOid)(oid).collection)));
288
+ this.context.log('changes to collections', affectedCollections);
289
+ this.context.entityEvents.emit('collectionsChanged', affectedCollections);
290
+ };
291
+ this.addLocalOperations = async (operations) => {
292
+ this.log('Adding local operations', operations.length);
293
+ this.addOperationsToOpenCaches(operations, {
294
+ isLocal: true,
295
+ confirmed: false,
296
+ });
297
+ this.operationBatcher.add({
298
+ key: this.currentBatchKey,
299
+ items: operations,
300
+ });
301
+ };
302
+ this.batch = ({ undoable = true, batchName = (0, common_1.generateId)(), max = null, timeout = this.defaultBatchTimeout, } = {}) => {
303
+ const internalBatch = this.operationBatcher.add({
304
+ key: batchName,
305
+ max,
306
+ timeout,
307
+ items: [],
308
+ userData: { undoable },
309
+ });
310
+ const externalApi = {
311
+ run: (fn) => {
312
+ // while the provided function runs, operations are forwarded
313
+ // to the new batch instead of default. this relies on the function
314
+ // being synchronous.
315
+ this.currentBatchKey = batchName;
316
+ fn();
317
+ this.currentBatchKey = DEFAULT_BATCH_KEY;
318
+ return externalApi;
319
+ },
320
+ flush: async () => {
321
+ // before running a batch, the default operations must be flushed
322
+ // this better preserves undo history behavior...
323
+ // if we left the default batch open while flushing a named batch,
324
+ // then the default batch would be flushed after the named batch,
325
+ // and the default batch could contain operations both prior and
326
+ // after the named batch. this would result in a confusing undo
327
+ // history where the first undo might reverse changes before and
328
+ // after a set of other changes.
329
+ await this.operationBatcher.flush(DEFAULT_BATCH_KEY);
330
+ return internalBatch.flush();
331
+ },
332
+ discard: () => {
333
+ this.operationBatcher.discard(batchName);
334
+ },
335
+ };
336
+ return externalApi;
337
+ };
338
+ /**
339
+ * @deprecated use `batch` instead
340
+ */
341
+ this.flushPatches = async () => {
342
+ await this.operationBatcher.flush(this.currentBatchKey);
343
+ };
344
+ this.flushAllBatches = async () => {
345
+ await Promise.all(this.operationBatcher.flushAll());
346
+ };
347
+ this.flushOperations = async (operations, batchKey, meta) => {
348
+ if (!operations.length)
349
+ return;
350
+ this.log('Flushing operations', operations.length, 'to storage / sync');
351
+ // rewrite timestamps of all operations to now - this preserves
352
+ // the linear history of operations which are sent to the server.
353
+ // even if multiple batches are spun up in parallel and flushed
354
+ // after delay, the final operations in each one should reflect
355
+ // when the batch flushed, not when the changes were made.
356
+ // This also corresponds to user-observed behavior, since unconfirmed
357
+ // operations are applied universally after confirmed operations locally,
358
+ // so even operations which were made before a remote operation but
359
+ // have not been confirmed yet will appear to come after the remote one
360
+ // despite the provisional timestamp being earlier (see DocumentFamilyCache#computeView)
361
+ for (const op of operations) {
362
+ op.timestamp = this.meta.now;
363
+ }
364
+ await this.submitOperations(operations, meta);
365
+ };
366
+ this.submitOperations = async (operations, { undoable = true } = {}) => {
367
+ if (undoable) {
368
+ // FIXME: this is too slow and needs to be optimized.
369
+ this.undoHistory.addUndo(await this.createUndo(operations));
370
+ }
371
+ await this.meta.insertLocalOperation(operations);
372
+ // confirm the operations
373
+ this.addDataToOpenCaches({ operations, baselines: [] });
374
+ // recompute all affected documents for querying
375
+ const allDocumentOids = Array.from(new Set(operations.map((op) => (0, common_1.getOidRoot)(op.oid))));
376
+ for (const oid of allDocumentOids) {
377
+ await this.writeDocumentToStorage(oid);
378
+ }
379
+ // TODO: find a more efficient and straightforward way to update affected
380
+ // queries. Move to Metadata?
381
+ const affectedCollections = new Set(operations.map(({ oid }) => (0, common_1.decomposeOid)(oid).collection));
382
+ this.context.log('changes to collections', affectedCollections);
383
+ this.context.entityEvents.emit('collectionsChanged', Array.from(affectedCollections));
384
+ };
385
+ this.getInverseOperations = async (ops) => {
386
+ const grouped = (0, common_1.groupPatchesByIdentifier)(ops);
387
+ const inverseOps = [];
388
+ const getNow = () => this.meta.now;
389
+ for (const [oid, patches] of Object.entries(grouped)) {
390
+ const familyCache = await this.openFamilyCache(oid);
391
+ let { view, deleted } = familyCache.computeConfirmedView(oid);
392
+ const inverse = (0, common_1.getUndoOperations)(oid, view, patches, getNow);
393
+ inverseOps.unshift(...inverse);
394
+ }
395
+ return inverseOps;
396
+ };
397
+ this.createUndo = async (ops) => {
398
+ const inverseOps = await this.getInverseOperations(ops);
399
+ return async () => {
400
+ const redo = await this.createUndo(inverseOps);
401
+ await this.submitOperations(inverseOps.map((op) => {
402
+ op.timestamp = this.meta.now;
403
+ return op;
404
+ }),
405
+ // undos should not generate their own undo operations
406
+ // since they already calculate redo as the inverse.
407
+ { undoable: false });
408
+ return redo;
409
+ };
410
+ };
411
+ this.delete = async (oid, options) => {
412
+ (0, common_1.assert)(oid === (0, common_1.getOidRoot)(oid), 'Only root documents may be deleted via client methods');
413
+ // we need to get all sub-object oids to delete alongside the root
414
+ const allOids = await this.meta.getAllDocumentRelatedOids(oid);
415
+ const patches = this.meta.patchCreator.createDeleteAll(allOids);
416
+ // don't enqueue these, submit as distinct operation
417
+ await this.submitOperations(patches, options);
418
+ };
419
+ this.deleteAll = async (oids, options) => {
420
+ const allOids = await Promise.all(oids.map((oid) => this.meta.getAllDocumentRelatedOids(oid)));
421
+ const patches = this.meta.patchCreator.createDeleteAll(allOids.flat());
422
+ // don't enqueue these, submit as distinct operation
423
+ await this.submitOperations(patches, options);
424
+ };
425
+ this.reset = async () => {
426
+ this.context.log('warn', 'Resetting local database');
427
+ await this.resetStoredDocuments();
428
+ await this.refreshAllCaches(true);
429
+ // this.context.entityEvents.emit(
430
+ // 'collectionsChanged',
431
+ // Object.keys(this.schema.collections),
432
+ // );
433
+ };
434
+ this.destroy = async () => {
435
+ this._disposed = true;
436
+ for (const unsubscribe of this.unsubscribes) {
437
+ unsubscribe();
438
+ }
439
+ for (const cache of this.documentFamilyCaches.values()) {
440
+ cache.dispose();
441
+ }
442
+ this.documentFamilyCaches.clear();
443
+ await this.flushAllBatches();
444
+ };
445
+ this.handleRebase = (baselines) => {
446
+ this.log('debug', 'Reacting to rebases', baselines.length);
447
+ // update any open caches with new baseline. this will automatically
448
+ // drop operations before the baseline.
449
+ this.addBaselinesToOpenCaches(baselines, { isLocal: true });
450
+ };
451
+ this.resetStoredDocuments = async () => {
452
+ const tx = this.db.transaction(Object.keys(this.schema.collections), 'readwrite');
453
+ for (const collection of Object.keys(this.schema.collections)) {
454
+ const store = tx.objectStore(collection);
455
+ await (0, idb_js_1.storeRequestPromise)(store.clear());
456
+ }
457
+ };
458
+ this.refreshAllCaches = async (dropUnconfirmed = false, dropAll = false) => {
459
+ for (const [_, cache] of this.documentFamilyCaches) {
460
+ await this.refreshFamilyCache(cache, dropUnconfirmed, dropAll);
461
+ }
462
+ };
463
+ this.context = context;
464
+ this.defaultBatchTimeout = batchTimeout;
465
+ this.meta = meta;
466
+ this.files = files;
467
+ this.operationBatcher = new common_1.Batcher(this.flushOperations);
468
+ // initialize default batch
469
+ this.operationBatcher.add({
470
+ key: DEFAULT_BATCH_KEY,
471
+ items: [],
472
+ max: 100,
473
+ timeout: batchTimeout,
474
+ userData: { undoable: true },
475
+ });
476
+ this.unsubscribes.push(this.meta.subscribe('rebase', this.handleRebase));
477
+ }
478
+ }
479
+ exports.EntityStore = EntityStore;
480
480
  //# sourceMappingURL=EntityStore.js.map