@connecttomahdi/rxdb 17.0.0-beta.17 → 17.1.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 (379) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +47 -4
  3. package/CLAUDE.md +2 -0
  4. package/dist/cjs/change-event-buffer.js +2 -1
  5. package/dist/cjs/change-event-buffer.js.map +1 -1
  6. package/dist/cjs/custom-index.js +85 -12
  7. package/dist/cjs/custom-index.js.map +1 -1
  8. package/dist/cjs/doc-cache.js +117 -35
  9. package/dist/cjs/doc-cache.js.map +1 -1
  10. package/dist/cjs/event-reduce.js +10 -1
  11. package/dist/cjs/event-reduce.js.map +1 -1
  12. package/dist/cjs/plugin-helpers.js +16 -0
  13. package/dist/cjs/plugin-helpers.js.map +1 -1
  14. package/dist/cjs/plugins/attachments/index.js +3 -3
  15. package/dist/cjs/plugins/attachments/index.js.map +1 -1
  16. package/dist/cjs/plugins/cleanup/cleanup.js +5 -3
  17. package/dist/cjs/plugins/cleanup/cleanup.js.map +1 -1
  18. package/dist/cjs/plugins/crdt/index.js +52 -0
  19. package/dist/cjs/plugins/crdt/index.js.map +1 -1
  20. package/dist/cjs/plugins/dev-mode/check-query.js +7 -1
  21. package/dist/cjs/plugins/dev-mode/check-query.js.map +1 -1
  22. package/dist/cjs/plugins/dev-mode/check-schema.js +2 -1
  23. package/dist/cjs/plugins/dev-mode/check-schema.js.map +1 -1
  24. package/dist/cjs/plugins/dev-mode/error-messages.js +43 -5
  25. package/dist/cjs/plugins/dev-mode/error-messages.js.map +1 -1
  26. package/dist/cjs/plugins/encryption-crypto-js/index.js +22 -6
  27. package/dist/cjs/plugins/encryption-crypto-js/index.js.map +1 -1
  28. package/dist/cjs/plugins/leader-election/index.js +5 -5
  29. package/dist/cjs/plugins/leader-election/index.js.map +1 -1
  30. package/dist/cjs/plugins/local-documents/local-documents.js +20 -13
  31. package/dist/cjs/plugins/local-documents/local-documents.js.map +1 -1
  32. package/dist/cjs/plugins/migration-schema/migration-helpers.js +3 -0
  33. package/dist/cjs/plugins/migration-schema/migration-helpers.js.map +1 -1
  34. package/dist/cjs/plugins/migration-schema/rx-migration-state.js +1 -1
  35. package/dist/cjs/plugins/migration-schema/rx-migration-state.js.map +1 -1
  36. package/dist/cjs/plugins/pipeline/rx-pipeline.js +5 -1
  37. package/dist/cjs/plugins/pipeline/rx-pipeline.js.map +1 -1
  38. package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
  39. package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
  40. package/dist/cjs/plugins/replication/index.js +40 -2
  41. package/dist/cjs/plugins/replication/index.js.map +1 -1
  42. package/dist/cjs/plugins/replication-google-drive/document-handling.js +17 -6
  43. package/dist/cjs/plugins/replication-google-drive/document-handling.js.map +1 -1
  44. package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js +1 -1
  45. package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
  46. package/dist/cjs/plugins/replication-google-drive/google-drive-types.js.map +1 -1
  47. package/dist/cjs/plugins/replication-google-drive/signaling.js +4 -1
  48. package/dist/cjs/plugins/replication-google-drive/signaling.js.map +1 -1
  49. package/dist/cjs/plugins/replication-google-drive/upstream.js +7 -4
  50. package/dist/cjs/plugins/replication-google-drive/upstream.js.map +1 -1
  51. package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js +4 -1
  52. package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
  53. package/dist/cjs/plugins/state/rx-state.js +14 -3
  54. package/dist/cjs/plugins/state/rx-state.js.map +1 -1
  55. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js +10 -17
  56. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  57. package/dist/cjs/plugins/storage-memory/binary-search-bounds.js +112 -40
  58. package/dist/cjs/plugins/storage-memory/binary-search-bounds.js.map +1 -1
  59. package/dist/cjs/plugins/storage-memory/memory-helper.js +127 -40
  60. package/dist/cjs/plugins/storage-memory/memory-helper.js.map +1 -1
  61. package/dist/cjs/plugins/storage-memory/memory-indexes.js +1 -0
  62. package/dist/cjs/plugins/storage-memory/memory-indexes.js.map +1 -1
  63. package/dist/cjs/plugins/storage-memory/memory-types.js.map +1 -1
  64. package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js +97 -37
  65. package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
  66. package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js +42 -1
  67. package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
  68. package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js +7 -7
  69. package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
  70. package/dist/cjs/plugins/test-utils/config.js +1 -1
  71. package/dist/cjs/plugins/test-utils/config.js.map +1 -1
  72. package/dist/cjs/plugins/test-utils/performance.js +122 -92
  73. package/dist/cjs/plugins/test-utils/performance.js.map +1 -1
  74. package/dist/cjs/plugins/test-utils/schema-objects.js +1 -1
  75. package/dist/cjs/plugins/test-utils/schema-objects.js.map +1 -1
  76. package/dist/cjs/plugins/test-utils/test-util.js +62 -0
  77. package/dist/cjs/plugins/test-utils/test-util.js.map +1 -1
  78. package/dist/cjs/plugins/utils/utils-map.js +2 -2
  79. package/dist/cjs/plugins/utils/utils-map.js.map +1 -1
  80. package/dist/cjs/plugins/utils/utils-object-deep-equal.js +3 -2
  81. package/dist/cjs/plugins/utils/utils-object-deep-equal.js.map +1 -1
  82. package/dist/cjs/plugins/utils/utils-object-dot-prop.js +25 -0
  83. package/dist/cjs/plugins/utils/utils-object-dot-prop.js.map +1 -1
  84. package/dist/cjs/plugins/utils/utils-object.js +102 -27
  85. package/dist/cjs/plugins/utils/utils-object.js.map +1 -1
  86. package/dist/cjs/plugins/utils/utils-other.js +9 -4
  87. package/dist/cjs/plugins/utils/utils-other.js.map +1 -1
  88. package/dist/cjs/plugins/utils/utils-premium.js +1 -19
  89. package/dist/cjs/plugins/utils/utils-premium.js.map +1 -1
  90. package/dist/cjs/plugins/utils/utils-revision.js +20 -10
  91. package/dist/cjs/plugins/utils/utils-revision.js.map +1 -1
  92. package/dist/cjs/plugins/utils/utils-rxdb-version.js +1 -1
  93. package/dist/cjs/plugins/utils/utils-rxdb-version.js.map +1 -1
  94. package/dist/cjs/plugins/utils/utils-string.js +11 -8
  95. package/dist/cjs/plugins/utils/utils-string.js.map +1 -1
  96. package/dist/cjs/plugins/utils/utils-time.js +21 -16
  97. package/dist/cjs/plugins/utils/utils-time.js.map +1 -1
  98. package/dist/cjs/query-cache.js +6 -4
  99. package/dist/cjs/query-cache.js.map +1 -1
  100. package/dist/cjs/query-planner.js +2 -2
  101. package/dist/cjs/query-planner.js.map +1 -1
  102. package/dist/cjs/replication-protocol/downstream.js +1 -1
  103. package/dist/cjs/replication-protocol/downstream.js.map +1 -1
  104. package/dist/cjs/rx-collection-helper.js +11 -6
  105. package/dist/cjs/rx-collection-helper.js.map +1 -1
  106. package/dist/cjs/rx-collection.js +34 -6
  107. package/dist/cjs/rx-collection.js.map +1 -1
  108. package/dist/cjs/rx-database.js +40 -7
  109. package/dist/cjs/rx-database.js.map +1 -1
  110. package/dist/cjs/rx-document.js +10 -3
  111. package/dist/cjs/rx-document.js.map +1 -1
  112. package/dist/cjs/rx-query-helper.js +35 -12
  113. package/dist/cjs/rx-query-helper.js.map +1 -1
  114. package/dist/cjs/rx-query-single-result.js +9 -2
  115. package/dist/cjs/rx-query-single-result.js.map +1 -1
  116. package/dist/cjs/rx-query.js +72 -29
  117. package/dist/cjs/rx-query.js.map +1 -1
  118. package/dist/cjs/rx-schema-helper.js +9 -3
  119. package/dist/cjs/rx-schema-helper.js.map +1 -1
  120. package/dist/cjs/rx-schema.js +1 -0
  121. package/dist/cjs/rx-schema.js.map +1 -1
  122. package/dist/cjs/rx-storage-helper.js +212 -129
  123. package/dist/cjs/rx-storage-helper.js.map +1 -1
  124. package/dist/cjs/types/rx-error.d.js.map +1 -1
  125. package/dist/cjs/types/rx-schema.d.js.map +1 -1
  126. package/dist/esm/change-event-buffer.js +2 -1
  127. package/dist/esm/change-event-buffer.js.map +1 -1
  128. package/dist/esm/custom-index.js +85 -12
  129. package/dist/esm/custom-index.js.map +1 -1
  130. package/dist/esm/doc-cache.js +118 -36
  131. package/dist/esm/doc-cache.js.map +1 -1
  132. package/dist/esm/event-reduce.js +10 -1
  133. package/dist/esm/event-reduce.js.map +1 -1
  134. package/dist/esm/plugin-helpers.js +16 -0
  135. package/dist/esm/plugin-helpers.js.map +1 -1
  136. package/dist/esm/plugins/attachments/index.js +3 -3
  137. package/dist/esm/plugins/attachments/index.js.map +1 -1
  138. package/dist/esm/plugins/cleanup/cleanup.js +5 -3
  139. package/dist/esm/plugins/cleanup/cleanup.js.map +1 -1
  140. package/dist/esm/plugins/crdt/index.js +52 -0
  141. package/dist/esm/plugins/crdt/index.js.map +1 -1
  142. package/dist/esm/plugins/dev-mode/check-query.js +7 -1
  143. package/dist/esm/plugins/dev-mode/check-query.js.map +1 -1
  144. package/dist/esm/plugins/dev-mode/check-schema.js +2 -1
  145. package/dist/esm/plugins/dev-mode/check-schema.js.map +1 -1
  146. package/dist/esm/plugins/dev-mode/error-messages.js +43 -5
  147. package/dist/esm/plugins/dev-mode/error-messages.js.map +1 -1
  148. package/dist/esm/plugins/encryption-crypto-js/index.js +22 -6
  149. package/dist/esm/plugins/encryption-crypto-js/index.js.map +1 -1
  150. package/dist/esm/plugins/leader-election/index.js +4 -4
  151. package/dist/esm/plugins/leader-election/index.js.map +1 -1
  152. package/dist/esm/plugins/local-documents/local-documents.js +20 -13
  153. package/dist/esm/plugins/local-documents/local-documents.js.map +1 -1
  154. package/dist/esm/plugins/migration-schema/migration-helpers.js +3 -0
  155. package/dist/esm/plugins/migration-schema/migration-helpers.js.map +1 -1
  156. package/dist/esm/plugins/migration-schema/rx-migration-state.js +1 -1
  157. package/dist/esm/plugins/migration-schema/rx-migration-state.js.map +1 -1
  158. package/dist/esm/plugins/pipeline/rx-pipeline.js +5 -1
  159. package/dist/esm/plugins/pipeline/rx-pipeline.js.map +1 -1
  160. package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
  161. package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
  162. package/dist/esm/plugins/replication/index.js +40 -2
  163. package/dist/esm/plugins/replication/index.js.map +1 -1
  164. package/dist/esm/plugins/replication-google-drive/document-handling.js +17 -6
  165. package/dist/esm/plugins/replication-google-drive/document-handling.js.map +1 -1
  166. package/dist/esm/plugins/replication-google-drive/google-drive-helper.js +1 -1
  167. package/dist/esm/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
  168. package/dist/esm/plugins/replication-google-drive/google-drive-types.js.map +1 -1
  169. package/dist/esm/plugins/replication-google-drive/signaling.js +4 -1
  170. package/dist/esm/plugins/replication-google-drive/signaling.js.map +1 -1
  171. package/dist/esm/plugins/replication-google-drive/upstream.js +7 -4
  172. package/dist/esm/plugins/replication-google-drive/upstream.js.map +1 -1
  173. package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js +4 -1
  174. package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
  175. package/dist/esm/plugins/state/rx-state.js +15 -4
  176. package/dist/esm/plugins/state/rx-state.js.map +1 -1
  177. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js +11 -18
  178. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  179. package/dist/esm/plugins/storage-memory/binary-search-bounds.js +107 -40
  180. package/dist/esm/plugins/storage-memory/binary-search-bounds.js.map +1 -1
  181. package/dist/esm/plugins/storage-memory/memory-helper.js +128 -41
  182. package/dist/esm/plugins/storage-memory/memory-helper.js.map +1 -1
  183. package/dist/esm/plugins/storage-memory/memory-indexes.js +1 -0
  184. package/dist/esm/plugins/storage-memory/memory-indexes.js.map +1 -1
  185. package/dist/esm/plugins/storage-memory/memory-types.js.map +1 -1
  186. package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js +90 -30
  187. package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
  188. package/dist/esm/plugins/storage-mongodb/mongodb-helper.js +39 -0
  189. package/dist/esm/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
  190. package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js +8 -8
  191. package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
  192. package/dist/esm/plugins/test-utils/config.js +1 -1
  193. package/dist/esm/plugins/test-utils/config.js.map +1 -1
  194. package/dist/esm/plugins/test-utils/performance.js +122 -92
  195. package/dist/esm/plugins/test-utils/performance.js.map +1 -1
  196. package/dist/esm/plugins/test-utils/schema-objects.js +1 -1
  197. package/dist/esm/plugins/test-utils/schema-objects.js.map +1 -1
  198. package/dist/esm/plugins/test-utils/test-util.js +59 -0
  199. package/dist/esm/plugins/test-utils/test-util.js.map +1 -1
  200. package/dist/esm/plugins/utils/utils-map.js +2 -2
  201. package/dist/esm/plugins/utils/utils-map.js.map +1 -1
  202. package/dist/esm/plugins/utils/utils-object-deep-equal.js +3 -2
  203. package/dist/esm/plugins/utils/utils-object-deep-equal.js.map +1 -1
  204. package/dist/esm/plugins/utils/utils-object-dot-prop.js +25 -0
  205. package/dist/esm/plugins/utils/utils-object-dot-prop.js.map +1 -1
  206. package/dist/esm/plugins/utils/utils-object.js +102 -27
  207. package/dist/esm/plugins/utils/utils-object.js.map +1 -1
  208. package/dist/esm/plugins/utils/utils-other.js +9 -4
  209. package/dist/esm/plugins/utils/utils-other.js.map +1 -1
  210. package/dist/esm/plugins/utils/utils-premium.js +1 -19
  211. package/dist/esm/plugins/utils/utils-premium.js.map +1 -1
  212. package/dist/esm/plugins/utils/utils-revision.js +20 -10
  213. package/dist/esm/plugins/utils/utils-revision.js.map +1 -1
  214. package/dist/esm/plugins/utils/utils-rxdb-version.js +1 -1
  215. package/dist/esm/plugins/utils/utils-rxdb-version.js.map +1 -1
  216. package/dist/esm/plugins/utils/utils-string.js +11 -8
  217. package/dist/esm/plugins/utils/utils-string.js.map +1 -1
  218. package/dist/esm/plugins/utils/utils-time.js +21 -16
  219. package/dist/esm/plugins/utils/utils-time.js.map +1 -1
  220. package/dist/esm/query-cache.js +7 -5
  221. package/dist/esm/query-cache.js.map +1 -1
  222. package/dist/esm/query-planner.js +2 -2
  223. package/dist/esm/query-planner.js.map +1 -1
  224. package/dist/esm/replication-protocol/downstream.js +1 -1
  225. package/dist/esm/replication-protocol/downstream.js.map +1 -1
  226. package/dist/esm/rx-collection-helper.js +12 -7
  227. package/dist/esm/rx-collection-helper.js.map +1 -1
  228. package/dist/esm/rx-collection.js +35 -7
  229. package/dist/esm/rx-collection.js.map +1 -1
  230. package/dist/esm/rx-database.js +40 -7
  231. package/dist/esm/rx-database.js.map +1 -1
  232. package/dist/esm/rx-document.js +11 -4
  233. package/dist/esm/rx-document.js.map +1 -1
  234. package/dist/esm/rx-query-helper.js +35 -12
  235. package/dist/esm/rx-query-helper.js.map +1 -1
  236. package/dist/esm/rx-query-single-result.js +10 -3
  237. package/dist/esm/rx-query-single-result.js.map +1 -1
  238. package/dist/esm/rx-query.js +72 -29
  239. package/dist/esm/rx-query.js.map +1 -1
  240. package/dist/esm/rx-schema-helper.js +9 -3
  241. package/dist/esm/rx-schema-helper.js.map +1 -1
  242. package/dist/esm/rx-schema.js +1 -0
  243. package/dist/esm/rx-schema.js.map +1 -1
  244. package/dist/esm/rx-storage-helper.js +176 -94
  245. package/dist/esm/rx-storage-helper.js.map +1 -1
  246. package/dist/esm/types/rx-error.d.js.map +1 -1
  247. package/dist/esm/types/rx-schema.d.js.map +1 -1
  248. package/dist/types/custom-index.d.ts +5 -0
  249. package/dist/types/doc-cache.d.ts +1 -1
  250. package/dist/types/index.d.ts +25 -26
  251. package/dist/types/plugins/dev-mode/error-messages.d.ts +36 -0
  252. package/dist/types/plugins/leader-election/index.d.ts +1 -0
  253. package/dist/types/plugins/replication-google-drive/document-handling.d.ts +4 -1
  254. package/dist/types/plugins/replication-google-drive/google-drive-types.d.ts +1 -0
  255. package/dist/types/plugins/state/rx-state.d.ts +1 -1
  256. package/dist/types/plugins/storage-denokv/index.d.ts +1 -1
  257. package/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts +1 -1
  258. package/dist/types/plugins/storage-localstorage/index.d.ts +1 -1
  259. package/dist/types/plugins/storage-memory/binary-search-bounds.d.ts +21 -10
  260. package/dist/types/plugins/storage-memory/memory-helper.d.ts +7 -3
  261. package/dist/types/plugins/storage-memory/memory-types.d.ts +5 -0
  262. package/dist/types/plugins/storage-mongodb/mongodb-helper.d.ts +9 -1
  263. package/dist/types/plugins/storage-mongodb/rx-storage-instance-mongodb.d.ts +2 -2
  264. package/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts +1 -1
  265. package/dist/types/plugins/storage-remote/rx-storage-remote.d.ts +1 -1
  266. package/dist/types/plugins/storage-sqlite/index.d.ts +1 -1
  267. package/dist/types/plugins/test-utils/performance.d.ts +36 -0
  268. package/dist/types/plugins/test-utils/test-util.d.ts +17 -0
  269. package/dist/types/plugins/utils/utils-object.d.ts +8 -3
  270. package/dist/types/plugins/utils/utils-premium.d.ts +0 -2
  271. package/dist/types/plugins/utils/utils-rxdb-version.d.ts +1 -1
  272. package/dist/types/rx-database.d.ts +1 -1
  273. package/dist/types/rx-query-single-result.d.ts +1 -1
  274. package/dist/types/rx-query.d.ts +3 -2
  275. package/dist/types/rx-storage-helper.d.ts +15 -0
  276. package/eslint.config.mjs +2 -1
  277. package/package.json +732 -729
  278. package/scripts/check-code-block-line-length.js +91 -0
  279. package/scripts/check-em-dashes.js +53 -0
  280. package/scripts/docs-fetch-git-history.mjs +36 -0
  281. package/scripts/install-foundationdb.sh +0 -6
  282. package/scripts/notify-indexnow.mjs +171 -0
  283. package/scripts/start-foundationdb-docker.sh +73 -0
  284. package/src/change-event-buffer.ts +4 -1
  285. package/src/custom-index.ts +93 -16
  286. package/src/doc-cache.ts +117 -41
  287. package/src/event-reduce.ts +10 -1
  288. package/src/plugin-helpers.ts +10 -0
  289. package/src/plugins/attachments/index.ts +10 -12
  290. package/src/plugins/cleanup/cleanup.ts +5 -3
  291. package/src/plugins/crdt/index.ts +55 -0
  292. package/src/plugins/dev-mode/check-query.ts +7 -1
  293. package/src/plugins/dev-mode/check-schema.ts +2 -1
  294. package/src/plugins/dev-mode/error-messages.ts +45 -5
  295. package/src/plugins/encryption-crypto-js/index.ts +18 -6
  296. package/src/plugins/leader-election/index.ts +9 -8
  297. package/src/plugins/local-documents/local-documents.ts +21 -12
  298. package/src/plugins/migration-schema/migration-helpers.ts +3 -0
  299. package/src/plugins/migration-schema/rx-migration-state.ts +1 -1
  300. package/src/plugins/pipeline/rx-pipeline.ts +5 -1
  301. package/src/plugins/query-builder/mquery/nosql-query-builder.ts +8 -2
  302. package/src/plugins/replication/index.ts +41 -3
  303. package/src/plugins/replication-google-drive/document-handling.ts +17 -5
  304. package/src/plugins/replication-google-drive/google-drive-helper.ts +1 -1
  305. package/src/plugins/replication-google-drive/google-drive-types.ts +1 -0
  306. package/src/plugins/replication-google-drive/signaling.ts +4 -1
  307. package/src/plugins/replication-google-drive/upstream.ts +7 -4
  308. package/src/plugins/replication-microsoft-onedrive/signaling.ts +4 -1
  309. package/src/plugins/state/rx-state.ts +17 -5
  310. package/src/plugins/storage-dexie/rx-storage-instance-dexie.ts +0 -27
  311. package/src/plugins/storage-memory/binary-search-bounds.ts +105 -40
  312. package/src/plugins/storage-memory/memory-helper.ts +158 -67
  313. package/src/plugins/storage-memory/memory-indexes.ts +1 -0
  314. package/src/plugins/storage-memory/memory-types.ts +5 -0
  315. package/src/plugins/storage-memory/rx-storage-instance-memory.ts +104 -53
  316. package/src/plugins/storage-mongodb/mongodb-helper.ts +43 -1
  317. package/src/plugins/storage-mongodb/rx-storage-instance-mongodb.ts +11 -9
  318. package/src/plugins/test-utils/config.ts +2 -1
  319. package/src/plugins/test-utils/performance.ts +159 -85
  320. package/src/plugins/test-utils/schema-objects.ts +1 -1
  321. package/src/plugins/test-utils/test-util.ts +71 -0
  322. package/src/plugins/utils/utils-map.ts +2 -2
  323. package/src/plugins/utils/utils-object-deep-equal.ts +2 -4
  324. package/src/plugins/utils/utils-object-dot-prop.ts +25 -0
  325. package/src/plugins/utils/utils-object.ts +103 -28
  326. package/src/plugins/utils/utils-other.ts +9 -4
  327. package/src/plugins/utils/utils-premium.ts +11 -37
  328. package/src/plugins/utils/utils-revision.ts +20 -9
  329. package/src/plugins/utils/utils-rxdb-version.ts +1 -1
  330. package/src/plugins/utils/utils-string.ts +11 -9
  331. package/src/plugins/utils/utils-time.ts +21 -17
  332. package/src/query-cache.ts +6 -5
  333. package/src/query-planner.ts +2 -2
  334. package/src/replication-protocol/downstream.ts +1 -1
  335. package/src/rx-collection-helper.ts +12 -6
  336. package/src/rx-collection.ts +39 -8
  337. package/src/rx-database.ts +49 -17
  338. package/src/rx-document.ts +12 -3
  339. package/src/rx-query-helper.ts +36 -15
  340. package/src/rx-query-single-result.ts +10 -3
  341. package/src/rx-query.ts +48 -8
  342. package/src/rx-schema-helper.ts +7 -4
  343. package/src/rx-schema.ts +1 -0
  344. package/src/rx-storage-helper.ts +210 -139
  345. package/src/types/rx-error.d.ts +3 -0
  346. package/src/types/rx-schema.d.ts +5 -0
  347. package/dist/esm/package.json +0 -1
  348. package/dist/types/types/conflict-handling.d.ts +0 -48
  349. package/dist/types/types/couchdb.d.ts +0 -293
  350. package/dist/types/types/index.d.ts +0 -32
  351. package/dist/types/types/modules/index.d.ts +0 -0
  352. package/dist/types/types/modules/mocha.parallel.d.ts +0 -1
  353. package/dist/types/types/plugins/backup.d.ts +0 -35
  354. package/dist/types/types/plugins/cleanup.d.ts +0 -38
  355. package/dist/types/types/plugins/crdt.d.ts +0 -76
  356. package/dist/types/types/plugins/dexie.d.ts +0 -30
  357. package/dist/types/types/plugins/local-documents.d.ts +0 -49
  358. package/dist/types/types/plugins/migration.d.ts +0 -14
  359. package/dist/types/types/plugins/reactivity.d.ts +0 -40
  360. package/dist/types/types/plugins/replication-graphql.d.ts +0 -98
  361. package/dist/types/types/plugins/replication.d.ts +0 -175
  362. package/dist/types/types/plugins/state.d.ts +0 -4
  363. package/dist/types/types/plugins/update.d.ts +0 -23
  364. package/dist/types/types/plugins/webmcp.d.ts +0 -40
  365. package/dist/types/types/query-planner.d.ts +0 -47
  366. package/dist/types/types/replication-protocol.d.ts +0 -296
  367. package/dist/types/types/rx-attachment.d.ts +0 -46
  368. package/dist/types/types/rx-change-event.d.ts +0 -85
  369. package/dist/types/types/rx-collection.d.ts +0 -117
  370. package/dist/types/types/rx-database-internal-store.d.ts +0 -54
  371. package/dist/types/types/rx-database.d.ts +0 -124
  372. package/dist/types/types/rx-document.d.ts +0 -160
  373. package/dist/types/types/rx-error.d.ts +0 -222
  374. package/dist/types/types/rx-plugin.d.ts +0 -167
  375. package/dist/types/types/rx-query.d.ts +0 -144
  376. package/dist/types/types/rx-schema.d.ts +0 -209
  377. package/dist/types/types/rx-storage.d.ts +0 -347
  378. package/dist/types/types/rx-storage.interface.d.ts +0 -312
  379. package/dist/types/types/util.d.ts +0 -180
@@ -562,7 +562,7 @@ export class RxDatabaseBase<
562
562
  return this.closePromise;
563
563
  }
564
564
 
565
- const { promise, resolve } = createPromiseWithResolvers<boolean>();
565
+ const { promise, resolve, reject } = createPromiseWithResolvers<boolean>();
566
566
  const resolveClosePromise = (result: boolean) => {
567
567
  if (this.onClosed) {
568
568
  this.onClosed();
@@ -598,18 +598,42 @@ export class RxDatabaseBase<
598
598
  /**
599
599
  * First wait until the database is idle
600
600
  */
601
- return this.requestIdlePromise()
602
- .then(() => Promise.all(this.onClose.map(fn => fn())))
603
- // close all collections
604
- .then(() => Promise.all(
605
- Object.keys(this.collections as any)
606
- .map(key => (this.collections as any)[key])
607
- .map(col => col.close())
608
- ))
609
- // close internal storage instances
610
- .then(() => this.internalStore.close())
611
- .then(() => resolveClosePromise(true));
612
- })();
601
+ await this.requestIdlePromise();
602
+
603
+ let closingError: Error | null = null;
604
+ try {
605
+ await Promise.all(this.onClose.map(fn => fn()));
606
+ } catch (err: unknown) {
607
+ closingError = err as Error;
608
+ }
609
+
610
+ // close all collections
611
+ await Promise.all(
612
+ Object.keys(this.collections as any)
613
+ .map(key => (this.collections as any)[key])
614
+ .map(col => col.close())
615
+ );
616
+
617
+ // close internal storage instances
618
+ await this.internalStore.close();
619
+
620
+ if (closingError) {
621
+ throw closingError;
622
+ }
623
+ resolveClosePromise(true);
624
+ })().catch((err) => {
625
+ /**
626
+ * If an error occurs during closing,
627
+ * we still have to mark the database as closed
628
+ * and clean up the instance tracking so that
629
+ * a new database with the same name can be created.
630
+ */
631
+ if (this.onClosed) {
632
+ this.onClosed();
633
+ }
634
+ this.closed = true;
635
+ reject(err);
636
+ });
613
637
 
614
638
  return promise;
615
639
  }
@@ -618,10 +642,18 @@ export class RxDatabaseBase<
618
642
  * deletes the database and its stored data.
619
643
  * Returns the names of all removed collections.
620
644
  */
621
- remove(): Promise<string[]> {
622
- return this
623
- .close()
624
- .then(() => removeRxDatabase(this.name, this.storage, this.multiInstance, this.password));
645
+ async remove(): Promise<string[]> {
646
+ /**
647
+ * Collect all collection onRemove handlers before closing,
648
+ * because close() will clear the collections and unsubscribe
649
+ * all listeners, making it impossible to trigger onRemove afterwards.
650
+ */
651
+ const collections = Object.values(this.collections as any) as RxCollection[];
652
+ await this.close();
653
+ await Promise.all(
654
+ collections.map(col => Promise.all(col.onRemove.map(fn => fn())))
655
+ );
656
+ return removeRxDatabase(this.name, this.storage, this.multiInstance, this.password);
625
657
  }
626
658
 
627
659
  get asRxDatabase(): RxDatabase<
@@ -13,6 +13,7 @@ import {
13
13
  trimDots,
14
14
  pluginMissing,
15
15
  flatClone,
16
+ deepEqual,
16
17
  PROMISE_RESOLVE_NULL,
17
18
  RXJS_SHARE_REPLAY_DEFAULTS,
18
19
  getProperty,
@@ -69,7 +70,8 @@ export const basePrototype = {
69
70
  return undefined;
70
71
  }
71
72
  return _this.$.pipe(
72
- map((d: any) => d._data._deleted)
73
+ map((d: any) => d._data._deleted),
74
+ distinctUntilChanged()
73
75
  );
74
76
  },
75
77
  get deleted$$() {
@@ -159,7 +161,14 @@ export const basePrototype = {
159
161
  return this.$
160
162
  .pipe(
161
163
  map((data: any) => getProperty(data, path)),
162
- distinctUntilChanged()
164
+ distinctUntilChanged((prev: any, curr: any) => {
165
+ /**
166
+ * Use deepEqual for non-primitive values (objects/arrays)
167
+ * because the default === comparison always fails across
168
+ * document revisions since each revision creates new object references.
169
+ */
170
+ return deepEqual(prev, curr);
171
+ })
163
172
  );
164
173
  },
165
174
  get$$(this: RxDocument, path: string) {
@@ -276,7 +285,7 @@ export const basePrototype = {
276
285
  _context?: string
277
286
  ): Promise<RxDocument> {
278
287
  const oldData = this._data;
279
- const newData: RxDocumentData<RxDocType> = await modifierFromPublicToInternal<RxDocType>(mutationFunction)(oldData) as any;
288
+ const newData: RxDocumentData<RxDocType> = await modifierFromPublicToInternal<RxDocType>(mutationFunction)(clone(oldData)) as any;
280
289
  return this._saveData(newData, oldData) as any;
281
290
  },
282
291
 
@@ -64,19 +64,10 @@ export function normalizeMangoQuery<RxDocType>(
64
64
  * For normalization, we have to normalize this
65
65
  * so our checks can perform properly.
66
66
  *
67
- *
68
- * TODO this must work recursive with nested queries that
69
- * contain multiple selectors via $and or $or etc.
67
+ * This works recursively for nested queries that
68
+ * contain multiple selectors via $and, $or, $nor or $not.
70
69
  */
71
- Object
72
- .entries(normalizedMangoQuery.selector)
73
- .forEach(([field, matcher]) => {
74
- if (typeof matcher !== 'object' || matcher === null) {
75
- (normalizedMangoQuery as any).selector[field] = {
76
- $eq: matcher
77
- };
78
- }
79
- });
70
+ normalizeQuerySelectorShorthands(normalizedMangoQuery.selector);
80
71
  }
81
72
 
82
73
  /**
@@ -144,11 +135,12 @@ export function normalizeMangoQuery<RxDocType>(
144
135
  schema.indexes.forEach(index => {
145
136
  const useIndex = isMaybeReadonlyArray(index) ? index : [index];
146
137
  const firstWrongIndex = useIndex.findIndex(indexField => !fieldsWithLogicalOperator.has(indexField));
138
+ const matchingFieldCount = firstWrongIndex === -1 ? useIndex.length : firstWrongIndex;
147
139
  if (
148
- firstWrongIndex > 0 &&
149
- firstWrongIndex > currentFieldsAmount
140
+ matchingFieldCount > 0 &&
141
+ matchingFieldCount > currentFieldsAmount
150
142
  ) {
151
- currentFieldsAmount = firstWrongIndex;
143
+ currentFieldsAmount = matchingFieldCount;
152
144
  currentBestIndexForSort = useIndex;
153
145
  }
154
146
  });
@@ -287,6 +279,35 @@ export async function runQueryUpdateFunction<RxDocType, RxQueryResult>(
287
279
  }
288
280
  }
289
281
 
282
+ /**
283
+ * Normalizes selector shorthand values recursively.
284
+ * Converts `{field: value}` to `{field: {$eq: value}}`
285
+ * and recurses into $and, $or, $nor arrays and $not objects.
286
+ */
287
+ const SELECTOR_ARRAY_OPERATORS = new Set(['$and', '$or', '$nor']);
288
+ function normalizeQuerySelectorShorthands(selector: any): void {
289
+ Object
290
+ .entries(selector)
291
+ .forEach(([field, matcher]) => {
292
+ if (typeof matcher !== 'object' || matcher === null) {
293
+ selector[field] = { $eq: matcher };
294
+ } else if (SELECTOR_ARRAY_OPERATORS.has(field) && Array.isArray(matcher)) {
295
+ (matcher as any[]).forEach(subSelector => normalizeQuerySelectorShorthands(subSelector));
296
+ } else if (field === '$not' && typeof matcher === 'object') {
297
+ normalizeQuerySelectorShorthands(matcher);
298
+ } else if (!field.startsWith('$') && typeof matcher === 'object') {
299
+ /**
300
+ * Recurse into field-level operator objects to normalize
301
+ * sub-selectors like $elemMatch which contain nested selectors.
302
+ */
303
+ const matcherObj = matcher as any;
304
+ if (matcherObj.$elemMatch && typeof matcherObj.$elemMatch === 'object') {
305
+ normalizeQuerySelectorShorthands(matcherObj.$elemMatch);
306
+ }
307
+ }
308
+ });
309
+ }
310
+
290
311
  /**
291
312
  * @returns a format of the query that can be used with the storage
292
313
  * when calling RxStorageInstance().query()
@@ -1,5 +1,5 @@
1
1
  import { mapDocumentsDataToCacheDocs } from './doc-cache.ts';
2
- import { now, overwriteGetterForCaching } from './plugins/utils/index.ts';
2
+ import { overwriteGetterForCaching } from './plugins/utils/index.ts';
3
3
  import { newRxError } from './rx-error.ts';
4
4
  import { RxQueryBase } from './rx-query.ts';
5
5
  import type {
@@ -7,6 +7,13 @@ import type {
7
7
  RxDocumentData
8
8
  } from './types';
9
9
 
10
+ /**
11
+ * Counter to create unique result IDs cheaply.
12
+ * Used instead of now() to avoid expensive timestamp computation
13
+ * when we only need uniqueness for change detection.
14
+ */
15
+ let _resultIdCounter = 0;
16
+
10
17
  /**
11
18
  * RxDB needs the query results in multiple formats.
12
19
  * Sometimes as a Map or an array with only the documentData.
@@ -16,11 +23,11 @@ import type {
16
23
  */
17
24
  export class RxQuerySingleResult<RxDocType> {
18
25
  /**
19
- * Time at which the current _result state was created.
26
+ * Unique identifier for this result state.
20
27
  * Used to determine if the result set has changed since X
21
28
  * so that we do not emit the same result multiple times on subscription.
22
29
  */
23
- public readonly time = now();
30
+ public readonly time = ++_resultIdCounter;
24
31
  public readonly documents: RxDocument<RxDocType>[];
25
32
  constructor(
26
33
  public readonly query: RxQueryBase<RxDocType, unknown>,
package/src/rx-query.ts CHANGED
@@ -93,12 +93,20 @@ export class RxQueryBase<
93
93
  public _creationTime = Date.now();
94
94
 
95
95
  // used in the query-cache to determine if the RxQuery can be cleaned up.
96
+ // 0 means never executed. Updated to an incrementing counter on each _ensureEqual call.
96
97
  public _lastEnsureEqual = 0;
97
98
 
98
99
  public uncached = false;
99
100
 
100
101
  // used to count the subscribers to the query
101
- public refCount$ = new BehaviorSubject(null);
102
+ // Lazy-initialized to avoid BehaviorSubject overhead for .exec()-only queries
103
+ public _refCount$: BehaviorSubject<null> | null = null;
104
+ public get refCount$(): BehaviorSubject<null> {
105
+ if (!this._refCount$) {
106
+ this._refCount$ = new BehaviorSubject<null>(null);
107
+ }
108
+ return this._refCount$;
109
+ }
102
110
 
103
111
  public isFindOneByIdQuery: false | string | string[];
104
112
 
@@ -395,12 +403,26 @@ export class RxQueryBase<
395
403
  * @overwrites itself with the actual value
396
404
  */
397
405
  toString(): string {
398
- const stringObj = sortObject({
399
- op: this.op,
400
- query: this.normalizedQuery,
401
- other: this.other
402
- }, true);
403
- const value = JSON.stringify(stringObj);
406
+ /**
407
+ * For findByIds queries, build the cache key directly from the IDs
408
+ * to avoid the expensive normalizeMangoQuery + sortObject + JSON.stringify.
409
+ * The selector structure is guaranteed by findByIds() which always creates
410
+ * { [primaryPath]: { $in: ids } }
411
+ */
412
+ let value: string;
413
+ if (this.op === 'findByIds') {
414
+ const ids: string[] = (this.mangoQuery.selector as any)[this.collection.schema.primaryPath].$in;
415
+ // slice() is needed because sort() mutates the array in-place
416
+ const sortedIds = ids.slice().sort();
417
+ value = '|findByIds|' + JSON.stringify(sortedIds);
418
+ } else {
419
+ const stringObj = sortObject({
420
+ op: this.op,
421
+ query: this.normalizedQuery,
422
+ other: this.other
423
+ }, true);
424
+ value = JSON.stringify(stringObj);
425
+ }
404
426
  this.toString = () => value;
405
427
  return value;
406
428
  }
@@ -448,7 +470,14 @@ export class RxQueryBase<
448
470
  * deletes all found documents
449
471
  * @return promise with deleted documents
450
472
  */
451
- async remove(): Promise<RxQueryResult> {
473
+ async remove(throwIfMissing?: boolean): Promise<RxQueryResult> {
474
+ if (throwIfMissing && this.op !== 'findOne') {
475
+ throw newRxError('QU9', {
476
+ collection: this.collection.name,
477
+ query: this.mangoQuery,
478
+ op: this.op
479
+ });
480
+ }
452
481
  const docs = await this.exec();
453
482
  if (Array.isArray(docs)) {
454
483
  const result = await this.collection.bulkRemove(docs);
@@ -458,6 +487,17 @@ export class RxQueryBase<
458
487
  return result.success as any;
459
488
  }
460
489
  } else {
490
+ // findOne() can return null when no document matches
491
+ if (!docs) {
492
+ if (throwIfMissing) {
493
+ throw newRxError('QU10', {
494
+ collection: this.collection.name,
495
+ query: this.mangoQuery,
496
+ op: this.op
497
+ });
498
+ }
499
+ return null as any;
500
+ }
461
501
  return (docs as any).remove();
462
502
  }
463
503
  }
@@ -291,7 +291,7 @@ export function fillWithDefaultSettings<T = any>(
291
291
 
292
292
  // make indexes unique
293
293
  const hasIndex = new Set<string>();
294
- useIndexes.filter(index => {
294
+ schemaObj.indexes = useIndexes.filter(index => {
295
295
  const indexStr = index.join(',');
296
296
  if (hasIndex.has(indexStr)) {
297
297
  return false;
@@ -301,8 +301,6 @@ export function fillWithDefaultSettings<T = any>(
301
301
  }
302
302
  });
303
303
 
304
- schemaObj.indexes = useIndexes;
305
-
306
304
  return schemaObj as any;
307
305
  }
308
306
 
@@ -367,7 +365,12 @@ export function fillObjectWithDefaults(rxSchema: RxSchema<any>, obj: any): any {
367
365
  for (let i = 0; i < defaultKeys.length; ++i) {
368
366
  const key = defaultKeys[i];
369
367
  if (obj[key] === undefined) {
370
- obj[key] = rxSchema.defaultValues[key];
368
+ const val = rxSchema.defaultValues[key];
369
+ if (typeof val === 'object' && val !== null) {
370
+ obj[key] = Array.isArray(val) ? val.slice() : { ...val };
371
+ } else {
372
+ obj[key] = val;
373
+ }
371
374
  }
372
375
  }
373
376
  return obj;
package/src/rx-schema.ts CHANGED
@@ -78,6 +78,7 @@ export class RxSchema<RxDocType = any> {
78
78
  const jsonSchema: any = flatClone(this.jsonSchema);
79
79
  jsonSchema.properties = flatClone(jsonSchema.properties);
80
80
  delete jsonSchema.properties._deleted;
81
+ delete jsonSchema.properties._rev;
81
82
  delete jsonSchema.properties._meta;
82
83
  delete jsonSchema.properties._attachments;
83
84